public static async Task <CacheValue <T> > GetAsync <T>(this ICacheManager cacheManager, string key, int cacheTime, Func <T> acquire, bool continueOnCapturedContext = false) { if (cacheTime <= 0) { return(new CacheValue <T>(acquire(), true)); } var cacheValue = await cacheManager.GetAsync <T>(key) .ConfigureAwait(continueOnCapturedContext); if (cacheValue.HasValue) { return(cacheValue); } cacheValue = new CacheValue <T>(acquire(), true); await cacheManager.SetAsync(key, cacheValue.Value, cacheTime) .ConfigureAwait(continueOnCapturedContext); return(cacheValue); }
public static CacheValue <T> Get <T>(this ICacheManager cacheManager, string key, int cacheTime, Func <T> acquire) { if (cacheTime <= 0) { return(new CacheValue <T>(acquire(), true)); } var cacheValue = cacheManager.Get <T>(key); if (cacheValue.HasValue) { return(cacheValue); } cacheValue = new CacheValue <T>(acquire(), true); cacheManager.Set(key, cacheValue.Value, cacheTime); return(cacheValue); }