frostfs-sdk-csharp/src/FrostFS.SDK.Client/Services/Shared/SessionCache.cs
Pavel Gross 87fe8db674
All checks were successful
DCO / DCO (pull_request) Successful in 21s
lint-build / dotnet8.0 (pull_request) Successful in 35s
lint-build / dotnet8.0 (push) Successful in 34s
/ Publish NuGet packages (push) Successful in 48s
[#43] Client: Memory optimization
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2025-03-31 11:40:04 +03:00

38 lines
878 B
C#

using System.Collections.Concurrent;
namespace FrostFS.SDK.Client;
internal sealed class SessionCache(ulong sessionExpirationDuration)
{
private ConcurrentDictionary<string, FrostFsSessionToken> _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;
}
}
}