using System; using System.Collections.Concurrent; namespace FrostFS.SDK.Client; internal sealed class SessionCache(ulong sessionExpirationDuration) { private ConcurrentDictionary _cache { get; } = []; internal ulong CurrentEpoch { get; set; } internal ulong TokenDuration { get; set; } = sessionExpirationDuration; internal bool Contains(string key) { return _cache.ContainsKey(key); } internal bool TryGetValue(string? key, out FrostFsSessionToken? value) { if (key == null) { value = null; return false; } var ok = _cache.TryGetValue(key, out value); return ok && value != null; } internal void SetValue(string? key, FrostFsSessionToken value) { if (key != null) { _cache[key] = value; } } internal void DeleteByPrefix(string prefix) { foreach (var key in _cache.Keys) { if (key.StartsWith(prefix, StringComparison.Ordinal)) { _cache.TryRemove(key, out var _); } } } }