[#28] Client: Apply code optimizations

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2024-11-18 16:57:20 +03:00
parent 766f61a5f7
commit 749000a090
57 changed files with 845 additions and 1116 deletions

View file

@ -1,23 +1,49 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
namespace FrostFS.SDK.Client;
internal struct SessionCache(ulong sessionExpirationDuration)
internal sealed class SessionCache(ulong sessionExpirationDuration)
{
internal Hashtable Cache { get; } = [];
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;
}
}
internal void DeleteByPrefix(string prefix)
{
foreach (var key in Cache.Keys)
foreach (var key in _cache.Keys)
{
if (((string)key).StartsWith(prefix, StringComparison.Ordinal))
if (key.StartsWith(prefix, StringComparison.Ordinal))
{
Cache.Remove(key);
_cache.TryRemove(key, out var _);
}
}
}