using LazyCache; namespace Azaion.CommonSecurity.Services; public interface ICache { T GetFromCache(string key, Func fetchFunc, TimeSpan? expiration = null); void Invalidate(string key); } public class MemoryCache : ICache { private readonly IAppCache _cache = new CachingService(); public T GetFromCache(string key, Func fetchFunc, TimeSpan? expiration = null) { expiration ??= TimeSpan.FromHours(4); return _cache.GetOrAdd(key, entry => { var result = fetchFunc(); entry.AbsoluteExpirationRelativeToNow = expiration; return result; }); } public void Invalidate(string key) => _cache.Remove(key); }