コード例 #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
        }
コード例 #6
0
        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()));
 }