[#28] Client: Apply code optimizations
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
766f61a5f7
commit
749000a090
57 changed files with 845 additions and 1116 deletions
|
@ -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 _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue