// TODO ADMIN LOGS make this thread safe or remove thread safety from the main partial class
private readonly Dictionary<int, List<SharedAdminLog>> _roundsLogCache = new(MaxRoundsCached);
+ private readonly Queue<int> _roundsLogCacheQueue = new();
private static readonly Gauge CacheRoundCount = Metrics.CreateGauge(
"admin_logs_cache_round_count",
// TODO ADMIN LOGS cache previous {MaxRoundsCached} rounds on startup
public void CacheNewRound()
{
- List<SharedAdminLog> list;
- var oldestRound = _currentRoundId - MaxRoundsCached;
+ List<SharedAdminLog>? list = null;
- if (_roundsLogCache.Remove(oldestRound, out var oldestList))
+ _roundsLogCacheQueue.Enqueue(_currentRoundId);
+ if (_roundsLogCacheQueue.Count > MaxRoundsCached)
{
- list = oldestList;
- list.Clear();
- }
- else
- {
- list = new List<SharedAdminLog>(LogListInitialSize);
+ var oldestRound = _roundsLogCacheQueue.Dequeue();
+ if (_roundsLogCache.Remove(oldestRound, out var oldestList))
+ {
+ list = oldestList;
+ list.Clear();
+ }
}
+ list ??= new List<SharedAdminLog>(LogListInitialSize);
+
_roundsLogCache.Add(_currentRoundId, list);
CacheRoundCount.Set(_roundsLogCache.Count);
}