private async Task <string> DownloadString(Uri url, bool forceRefresh = false) { return(await JsonCache.GetAsync(url.ToCacheKey(), () => _httpClient.GetStringAsync(url), DateTime.UtcNow.AddHours(6), forceRefresh)); }
public async Task SetCacheKeyTest() { //Clear the cache await JsonCache.ClearAll(); await JsonCache.Set("test", "result set"); var result = await JsonCache.GetAsync("test", () => LongRunningOperation("result 2")); Assert.AreEqual("result set", result); }
public async Task ForceGetTest() { //Clear the cache await JsonCache.ClearAll(); var result1 = await JsonCache.GetAsync("test", () => LongRunningOperation("result")); Assert.AreEqual("result", result1); var result2 = await JsonCache.GetAsync("test", () => LongRunningOperation("result 2"), forceRefresh : true); Assert.AreEqual("result 2", result2); //Not from cache }
public async Task GetCacheTest() { //Clear the cache await JsonCache.ClearAll(); var result1 = await JsonCache.GetAsync("test", () => LongRunningOperation("result")); Assert.AreEqual("result", result1); var result2 = await JsonCache.GetAsync("test", () => LongRunningOperation("result 2")); Assert.AreEqual("result", result2); }
public async Task DeleteCacheKeyTest() { //Clear the cache await JsonCache.ClearAll(); var result1 = await JsonCache.GetAsync("test", () => LongRunningOperation("result")); Assert.AreEqual("result", result1); await JsonCache.Delete("test"); var result2 = await JsonCache.GetAsync("test", () => LongRunningOperation("result 2")); Assert.AreEqual("result 2", result2); //Not from cache }
private async Task GetPrijs(PlannerSearch search) { ReisPrijs result = await PrijsLoader.LoadAsync(() => JsonCache.GetAsync(search.GetUniquePriceId(), () => _prijsService.GetPrijs(search))); this.Prijs = result; }
/// <summary> /// First return cached result, then refresh this result with live value /// </summary> private void CacheRefreshAction() { CacheRefreshResult = string.Empty; //Fire task //Will show loader in the UI CacheRefreshDataLoader.LoadCacheThenRefreshAsync(() => JsonCache.GetFromCache <string>("key6"), () => JsonCache.GetAsync("key6", () => LongRunningOperation(DateTime.Now.Second.ToString()), expireDate: DateTime.Now.AddDays(1), forceRefresh: true), x => { CacheRefreshResult = x; }); }
/// <summary> /// Get from cache with Exception result /// </summary> private async void CacheWithExceptionAction() { //Fire task //Will show loader in the UI string result = await CacheWithExceptionDataLoader.LoadAsync(() => JsonCache.GetAsync("samplekey_exception", () => LongRunningOperationWithException(), expireDate: DateTime.Now.AddDays(1))); }
/// <summary> /// Get data from cache (or insert into cache if it's not there yet) /// </summary> private async void CacheAction() { //Fire task //Will show loader in the UI string result = await CacheDataLoader.LoadAsync(() => JsonCache.GetAsync("samplekey", () => LongRunningOperation())); }