Path: redb-route/redb.Route.GenericFile/InMemoryGenericFileIdempotentRepository.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.GenericFile/InMemoryGenericFileIdempotentRepository.cs ---- using redb.Route.Abstractions; namespace redb.Route.GenericFile; /// /// In-memory idempotent repository for tracking processed files across all file-based transports. /// Tracks files by a composite key (path + last modified + size) to detect re-processing. /// Thread-safe via HashSet + lock. /// public sealed class InMemoryGenericFileIdempotentRepository : IIdempotentRepository { // Ordinal, not OrdinalIgnoreCase: the key embeds the file path, and every SFTP/FTP server // and every non-Windows file system is case-sensitive. Folding case there makes two real // files share one key, and the second one is skipped as a duplicate that it never was. private readonly HashSet _keys = new(StringComparer.Ordinal); private readonly object _lock = new(); /// Current number of tracked keys. public int Count { get { lock (_lock) return _keys.Count; } } /// public Task Add(string key, CancellationToken ct = default) { lock (_lock) { return Task.FromResult(_keys.Add(key)); } } /// public Task Confirm(string key, CancellationToken ct = default) => Task.CompletedTask; /// public Task Remove(string key, CancellationToken ct = default) { lock (_lock) { _keys.Remove(key); } return Task.CompletedTask; } /// public Task Contains(string key, CancellationToken ct = default) { lock (_lock) { return Task.FromResult(_keys.Contains(key)); } } /// public Task Clear(CancellationToken ct = default) { lock (_lock) { _keys.Clear(); } return Task.CompletedTask; } /// /// Generates the default idempotent key for a file. /// Format: "{fullPath}|{lastModifiedUtc:O}|{length}" /// public static string DefaultKey(GenericFileInfo file) { ArgumentNullException.ThrowIfNull(file); return $"{file.FullPath}|{file.LastModified:O}|{file.Length}"; } }