using LazyCache; namespace Azaion.Services; public interface ICache { Task GetFromCacheAsync(string key, Func> fetchFunc, TimeSpan? expiration = null); void Invalidate(string key); } public class MemoryCache : ICache { private readonly IAppCache _cache = new CachingService(); public async Task GetFromCacheAsync(string key, Func> 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); }