Reset cache

This commit is contained in:
Behzad Alizadeh
2026-04-26 19:47:19 +03:30
parent e52fb8f85c
commit 34c3d4e848
8 changed files with 122 additions and 61 deletions
@@ -29,4 +29,10 @@ public interface ICacheManager
/// Gets an item from the cache, or creates it if it doesn't exist.
/// </summary>
Task<TItem?> GetOrCreateAsync<TItem>(object key, Func<ICacheEntry, Task<TItem>> factory);
/// <summary>
/// remove an item from the cache
/// </summary>
/// <param name="key"></param>
void Remove(string key);
}
@@ -22,10 +22,17 @@ public class CacheManager(IMemoryCache memoryCache, IChangeTokenSignaler changeT
{
return changeTokenSignaler.TriggerTokenAsync(key, cancellationToken);
}
/// <inheritdoc />
public async Task<TItem?> GetOrCreateAsync<TItem>(object key, Func<ICacheEntry, Task<TItem>> factory)
{
return await memoryCache.GetOrCreateAsync(key, async entry => await factory(entry));
var result = await memoryCache.GetOrCreateAsync(key, async entry => await factory(entry));
return result;
}
/// <inheritdoc />
public void Remove(string key)
{
memoryCache.Remove(key);
}
}