예제 #1
0
 private async Task <string> DownloadString(Uri url, bool forceRefresh = false)
 {
     return(await JsonCache.GetAsync(url.ToCacheKey(),
                                     () => _httpClient.GetStringAsync(url),
                                     DateTime.UtcNow.AddHours(6),
                                     forceRefresh));
 }
예제 #2
0
        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);
        }
예제 #3
0
        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
        }
예제 #4
0
        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);
        }
예제 #5
0
        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;
        }
예제 #7
0
        /// <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;
            });
        }
예제 #8
0
 /// <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)));
 }
예제 #9
0
 /// <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()));
 }