Exemple #1
0
        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());
        }