fix memory/database leak with ranked player count cache

This commit is contained in:
RaidMax 2022-06-12 12:19:32 -05:00
parent b337e232a2
commit 6587187a34
2 changed files with 3 additions and 2 deletions

View File

@ -176,7 +176,7 @@ namespace IW4MAdmin.Application.Misc
.Where(rating => rating.Client.Level != EFClient.Permission.Banned)
.Where(rating => rating.Ranking != null)
.CountAsync(cancellationToken);
}, nameof(_rankedClientsCache), serverId is null ? null: new[] { (object)serverId }, _cacheTimeSpan, true);
}, nameof(_rankedClientsCache), serverId is null ? null: new[] { (object)serverId }, _cacheTimeSpan);
try
{

View File

@ -18,6 +18,7 @@ namespace Data.Helpers
private readonly IDatabaseContextFactory _contextFactory;
private readonly ConcurrentDictionary<string, Dictionary<object, CacheState<TReturnType>>> _cacheStates = new();
private readonly object _defaultKey = new();
private bool _autoRefresh;
private const int DefaultExpireMinutes = 15;
@ -58,7 +59,7 @@ namespace Data.Helpers
public void SetCacheItem(Func<DbSet<TEntityType>, CancellationToken, Task<TReturnType>> getter, string key,
IEnumerable<object> ids = null, TimeSpan? expirationTime = null, bool autoRefresh = false)
{
ids ??= new[] { new object() };
ids ??= new[] { _defaultKey };
if (!_cacheStates.ContainsKey(key))
{