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()); }
/// <summary> /// Initializes a new instance of the <see cref="BlogController" /> class. /// </summary> /// <param name="blogRepository">The blog repository.</param> /// <param name="tempDataProvider">The temporary data provider</param> /// <param name="webCache">Web cache to clear when modifying posts</param> /// <param name="comments">Disqus comments service</param> public BlogController(IBlogRepository blogRepository, ITempDataProvider tempDataProvider, IWebCache webCache, IDisqusComments comments) { _blogRepository = blogRepository; _webCache = webCache; _comments = comments; // TODO: This shouldn't be required to be passed in the constructor - Can set it as a property. TempDataProvider = tempDataProvider; }
protected BaseAsyncWebClient([NotNull] IWebCache cache) { if (cache == null) { throw new ArgumentNullException("cache"); } _cache = cache; }
public DataUploader( IWebRequest webRequest, IWebCache webCache, IInternetConnectivity internetConnectivity) { _webRequest = webRequest ?? throw new ArgumentNullException(nameof(webRequest)); _webCache = webCache ?? throw new ArgumentNullException(nameof(webCache)); _internetConnectivity = internetConnectivity ?? throw new ArgumentNullException(nameof(internetConnectivity)); }
private void UpdateSubPlaylistCache(Uri playlist) { if (_subPlaylistCache != null && !(_subPlaylistCache.WebReader.BaseAddress != playlist)) { return; } _subPlaylistCache?.WebReader.Dispose(); _subPlaylistCache = _webReader.CreateWebCache(playlist, ContentKind.Playlist); }
public OfflineUnsafeWebRequest( IWebRequest webRequest, IWebCache webCache, IInternetConnectivity internetConnectivity) { _webRequest = webRequest; _webCache = webCache; _internetConnectivity = internetConnectivity; }
protected BaseAsyncWebClient([NotNull] IWebCache cache) { if (cache == null) { throw new ArgumentNullException("cache"); } CallFactory = new RestfulCallFactory(); _cache = cache; }
public AsyncDataProvider([NotNull] IWebCache cache, [NotNull] UniversitiesCache universitiesCache) : base(cache) { if (universitiesCache == null) { throw new ArgumentNullException("universitiesCache"); } _universitiesCache = universitiesCache; _universitiesCache.Load(); }
private void UpdateSubPlaylistCache(Uri playlist) { if (this._subPlaylistCache != null && !(this._subPlaylistCache.WebReader.BaseAddress != playlist)) { return; } if (null != this._subPlaylistCache) { this._subPlaylistCache.WebReader.Dispose(); } this._subPlaylistCache = WebReaderExtensions.CreateWebCache(this._webReader, playlist, ContentKind.Playlist, (ContentType)null); }
public static IWebRequest WithOffline( this IWebRequest webRequest, IWebCache webCache, IInternetConnectivity internetConnectivity) { return(new OfflineUnsafeWebRequest( new OfflineSafeWebRequest( webRequest, webCache, internetConnectivity), webCache, internetConnectivity)); }
public CacheAbstraction(IWebCache iwebc) { _iwebCache = iwebc; }
public AsyncDataProvider([NotNull] IWebCache cache) : base(cache) { }
public CacheAbstraction(IWebCache webCache) { _iwebCache = webCache; }
void UpdateSubPlaylistCache(Uri playlist) { if (null == _subPlaylistCache || _subPlaylistCache.WebReader.BaseAddress != playlist) { if (null != _subPlaylistCache) _subPlaylistCache.WebReader.Dispose(); _subPlaylistCache = _webReader.CreateWebCache(playlist, ContentKind.Playlist, ContentType); } }
public QuizService(IWebCache webCache) { _webCache = webCache; LoadQuizzes(); }
public CacheAbstraction(IWebCache iCache) { iWebCache = iCache; }
public Task <TCached> ReadAsync <TCached>(Uri uri, Func <Uri, byte[], TCached> factory, ContentKind contentKind, ContentType contentType, CancellationToken cancellationToken) where TCached : class { TaskCompletionSource <TCached> tcs = (TaskCompletionSource <TCached>)null; bool lockTaken = false; Dictionary <Uri, WebCacheManager.CacheEntry> dictionary; WebCacheManager.CacheEntry cacheEntry; try { Monitor.Enter((object)(dictionary = this._cache), ref lockTaken); if (this._cache.TryGetValue(uri, out cacheEntry)) { if (cacheEntry.ReadTask.IsCompleted && cacheEntry.Age > TimeSpan.FromSeconds(5.0)) { tcs = new TaskCompletionSource <TCached>(); cacheEntry.ReadTask = (Task)tcs.Task; } } else { IWebCache webCache = WebReaderExtensions.CreateWebCache(this._webReader, uri, contentKind, contentType); tcs = new TaskCompletionSource <TCached>(); cacheEntry = new WebCacheManager.CacheEntry() { WebCache = webCache, ReadTask = (Task)tcs.Task }; this._cache[uri] = cacheEntry; } } finally { if (lockTaken) { Monitor.Exit((object)dictionary); } } if (null == tcs) { return((Task <TCached>)cacheEntry.ReadTask); } Task <TCached> task = cacheEntry.WebCache.ReadAsync <TCached>(factory, cancellationToken, (WebResponse)null); task.ContinueWith((Action <Task <TCached> >)(t => { cacheEntry.ResetTime(); if (null != t.Exception) { tcs.TrySetCanceled(); } else if (t.IsCanceled) { tcs.TrySetCanceled(); } else { tcs.TrySetResult(task.Result); } }), cancellationToken); return(tcs.Task); }
public AsyncWebClient([NotNull] IWebCache cache) : base(cache) { }