mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 15:46:31 +00:00
add MediaHash. Step1
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Azaion.Common.Services;
|
||||
public interface ICache
|
||||
{
|
||||
T GetFromCache<T>(string key, Func<T> fetchFunc, TimeSpan? expiration = null);
|
||||
Task<T> GetFromCacheAsync<T>(string key, Func<Task<T>> fetchFunc, TimeSpan? expiration = null);
|
||||
void Invalidate(string key);
|
||||
}
|
||||
|
||||
@@ -23,5 +24,16 @@ public class MemoryCache : ICache
|
||||
});
|
||||
}
|
||||
|
||||
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