public async Task <Response <TResult> > Execute <TApi, TResult>(Expression <Func <TApi, Task <TResult> > > executeApiMethod, bool invalidateCache = false) { if (!_refitCacheController.IsMethodCacheable(executeApiMethod)) { return(await _decoratedRestService.Execute(executeApiMethod, invalidateCache).ConfigureAwait(false)); } var cacheKey = _refitCacheController.GetCacheKey(executeApiMethod); if (invalidateCache) { await persistedCache.Delete(cacheKey); } else { var cachedValue = await persistedCache.Get <TResult>(cacheKey); if (cachedValue != null) { return(new Response <TResult>(cachedValue)); } } var restResponse = await _decoratedRestService.Execute(executeApiMethod); if (restResponse.IsSuccess) { var refitCacheAttributes = _refitCacheController.GetRefitCacheAttribute <TApi, TResult>(executeApiMethod); await persistedCache.Save(cacheKey, restResponse.Results, refitCacheAttributes.CacheAttribute.CacheTtl); } return(restResponse); }
public Task ClearCache<TApi, TResult>(Expression<Func<TApi, Task<TResult>>> forApiMethodCall){ if (!_refitCacheController.IsMethodCacheable(forApiMethodCall)) return Task.FromResult(true); var cacheKey = _refitCacheController.GetCacheKey(forApiMethodCall); return persistedCache.Delete(cacheKey); }