public async Task <ResponseContext> UseCachedAsync(string url, string postData, Func <Task <ResponseContext> > funcAsync, EnumCacheStrategy strategy = EnumCacheStrategy.CacheIfNotExist) { ResponseContext res = await this.GetCacheResponseContextAsync(url, postData); return(await CachedAsync(url, funcAsync, strategy, res)); }
async Task <ResponseContext> CachedAsync(string url, Func <Task <ResponseContext> > funcAsync, EnumCacheStrategy strategy, ResponseContext res) { if (res == null || string.IsNullOrWhiteSpace(res.StringContent) || strategy == EnumCacheStrategy.ForceNoCache) { if (funcAsync == null) { throw new Exception("You must to specify the function that results a string"); } try { res = await funcAsync(); res.RequestUrl = url; res.HasUsedCache = false; if (strategy == EnumCacheStrategy.CacheIfNotExist) { await this.SetCacheItemAsync(url, res); } } catch (Exception ex) { res = new ResponseContext(); res.RequestUrl = url; res.HasUsedCache = false; res.Exception = ex; } } return(res); }