add Cache.cs

fix hardware hash stack in the jwt token claims
This commit is contained in:
Alex Bezdieniezhnykh
2025-01-18 14:36:50 +02:00
parent 0945635a1c
commit 49de0351c1
7 changed files with 77 additions and 33 deletions
+27
View File
@@ -0,0 +1,27 @@
using LazyCache;
namespace Azaion.Services;
public interface ICache
{
Task<T> GetFromCacheAsync<T>(string key, Func<Task<T>> fetchFunc, TimeSpan? expiration = null);
void Invalidate(string key);
}
public class MemoryCache : ICache
{
private readonly IAppCache _cache = new CachingService();
public async Task<T> GetFromCacheAsync<T>(string key, Func<Task<T>> fetchFunc, TimeSpan? expiration = null)
{
expiration ??= TimeSpan.FromHours(4);
return await _cache.GetOrAddAsync(key, async entry =>
{
var result = await fetchFunc();
entry.AbsoluteExpirationRelativeToNow = expiration;
return result;
});
}
public void Invalidate(string key) => _cache.Remove(key);
}