mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 09:26:34 +00:00
add Cache.cs
fix hardware hash stack in the jwt token claims
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user