private async Task <string> GetPageContent(string url) { IWebRequestHelper webRequestHelper = ServiceLocator.Current.GetInstance <IWebRequestHelper>(); IWebCache webCache = ServiceLocator.Current.GetInstance <IWebCache>(); ICacheItem cacheItem = await webCache.Get(url, TimeSpan.FromDays(CacheDurationDays), k => { return(webRequestHelper.GetDataAsync(url, null, null, 30000, null, new Dictionary <HttpRequestHeader, string> { { HttpRequestHeader.Accept, "application/json" } })); }); if (cacheItem == null) { return(null); } if (cacheItem.Data == null) { return(null); } return(cacheItem.GetUTF8()); }
private void LoadQuizzes() { _quizzes = _webCache.Get <List <Quiz> >(QuizKey); if (_quizzes == null) { string path = HttpContext.Current.Server.MapPath(QuizPath); using (StreamReader file = File.OpenText(path)) { var serializer = new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver() }; _quizzes = (List <Quiz>)serializer.Deserialize(file, typeof(List <Quiz>)); } _webCache.Insert(QuizKey, _quizzes); } }