fix memory/database leak with ranked player count cache
This commit is contained in:
parent
b337e232a2
commit
6587187a34
@ -176,7 +176,7 @@ namespace IW4MAdmin.Application.Misc
|
|||||||
.Where(rating => rating.Client.Level != EFClient.Permission.Banned)
|
.Where(rating => rating.Client.Level != EFClient.Permission.Banned)
|
||||||
.Where(rating => rating.Ranking != null)
|
.Where(rating => rating.Ranking != null)
|
||||||
.CountAsync(cancellationToken);
|
.CountAsync(cancellationToken);
|
||||||
}, nameof(_rankedClientsCache), serverId is null ? null: new[] { (object)serverId }, _cacheTimeSpan, true);
|
}, nameof(_rankedClientsCache), serverId is null ? null: new[] { (object)serverId }, _cacheTimeSpan);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ namespace Data.Helpers
|
|||||||
private readonly IDatabaseContextFactory _contextFactory;
|
private readonly IDatabaseContextFactory _contextFactory;
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<string, Dictionary<object, CacheState<TReturnType>>> _cacheStates = new();
|
private readonly ConcurrentDictionary<string, Dictionary<object, CacheState<TReturnType>>> _cacheStates = new();
|
||||||
|
private readonly object _defaultKey = new();
|
||||||
|
|
||||||
private bool _autoRefresh;
|
private bool _autoRefresh;
|
||||||
private const int DefaultExpireMinutes = 15;
|
private const int DefaultExpireMinutes = 15;
|
||||||
@ -58,7 +59,7 @@ namespace Data.Helpers
|
|||||||
public void SetCacheItem(Func<DbSet<TEntityType>, CancellationToken, Task<TReturnType>> getter, string key,
|
public void SetCacheItem(Func<DbSet<TEntityType>, CancellationToken, Task<TReturnType>> getter, string key,
|
||||||
IEnumerable<object> ids = null, TimeSpan? expirationTime = null, bool autoRefresh = false)
|
IEnumerable<object> ids = null, TimeSpan? expirationTime = null, bool autoRefresh = false)
|
||||||
{
|
{
|
||||||
ids ??= new[] { new object() };
|
ids ??= new[] { _defaultKey };
|
||||||
|
|
||||||
if (!_cacheStates.ContainsKey(key))
|
if (!_cacheStates.ContainsKey(key))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user