コード例 #1
0
ファイル: DataCacheTest.cs プロジェクト: sanjayasl/Q42.WinRT
        public async Task ClearCacheMaxAgeTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            await DataCache.Set("first", "first result");

            await DataCache.Set("second", "second result");

            await DataCache.Clear(TimeSpan.FromHours(1));

            //Nothing is gone
            var firstResult = await DataCache.GetFromCache <string>("first");

            Assert.IsNotNull(firstResult);

            //Second is still available
            var secondResult = await DataCache.GetFromCache <string>("second");

            Assert.AreEqual("second result", secondResult);

            //Clear everything until now
            await DataCache.Clear(TimeSpan.FromSeconds(0));

            //Everything should be gone
            firstResult = await DataCache.GetFromCache <string>("first");

            Assert.IsNull(firstResult);

            secondResult = await DataCache.GetFromCache <string>("second");

            Assert.IsNull(secondResult);
        }
コード例 #2
0
ファイル: DataCacheTest.cs プロジェクト: sanjayasl/Q42.WinRT
        public async Task DeleteNotExistingCacheKeyTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            await DataCache.Delete("not_exist");
        }
コード例 #3
0
        private async void ClearCacheButton_OnClick(object sender, RoutedEventArgs e)
        {
            ViewModel.IsLoading = true;
            await DataCache.ClearAll();

            ViewModel.IsLoading = false;
            MessageBox.Show("Web data cache cleared.");
        }
コード例 #4
0
ファイル: DataCacheTest.cs プロジェクト: maduhu/Q42.WinRT
        public async Task SetExpireDateInValidTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            await DataCache.Set("test", "result set", DateTime.Now.AddDays(-1));

            var emptyResult = await DataCache.GetFromCache <string>("test");

            Assert.AreEqual(null, emptyResult);
        }
コード例 #5
0
ファイル: DataCacheTest.cs プロジェクト: maduhu/Q42.WinRT
        public async Task SetCacheKeyTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            await DataCache.Set("test", "result set");

            var result = await DataCache.GetAsync("test", () => LongRunningOperation("result 2"));

            Assert.AreEqual("result set", result);
        }
コード例 #6
0
ファイル: DataCacheTest.cs プロジェクト: maduhu/Q42.WinRT
        public async Task GetCacheNullValueTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            var result1 = await DataCache.GetAsync("test", () => LongRunningOperation(null));

            Assert.AreEqual(null, result1);

            var result2 = await DataCache.GetAsync("test", () => LongRunningOperation("result 2"));

            Assert.AreEqual("result 2", result2);
        }
コード例 #7
0
ファイル: DataCacheTest.cs プロジェクト: maduhu/Q42.WinRT
        public async Task ForceGetTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            var result1 = await DataCache.GetAsync("test", () => LongRunningOperation("result"));

            Assert.AreEqual("result", result1);

            var result2 = await DataCache.GetAsync("test", () => LongRunningOperation("result 2"), forceRefresh : true);

            Assert.AreEqual("result 2", result2); //Not from cache
        }
コード例 #8
0
ファイル: DataCacheTest.cs プロジェクト: maduhu/Q42.WinRT
        public async Task GetCacheKeyTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            var emptyResult = await DataCache.GetFromCache <string>("test");

            Assert.AreEqual(null, emptyResult);

            await DataCache.Set("test", "result set");

            var result = await DataCache.GetFromCache <string>("test");

            Assert.AreEqual("result set", result);
        }
コード例 #9
0
ファイル: DataCacheTest.cs プロジェクト: maduhu/Q42.WinRT
        public async Task DeleteCacheKeyTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            var result1 = await DataCache.GetAsync("test", () => LongRunningOperation("result"));

            Assert.AreEqual("result", result1);

            await DataCache.Delete("test");


            var result2 = await DataCache.GetAsync("test", () => LongRunningOperation("result 2"));

            Assert.AreEqual("result 2", result2); //Not from cache
        }
コード例 #10
0
ファイル: DataCacheTest.cs プロジェクト: sanjayasl/Q42.WinRT
        public async Task GetCacheWrongObjectTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            var result1 = await DataCache.GetAsync("test", () => LongRunningOperation("result"));

            Assert.AreEqual("result", result1);

            var secondResult = DateTime.Now;

            var result2 = await DataCache.GetAsync("test", () => LongRunningOperationDateTimeResult(secondResult));

            //Cache fails, because it can't create a DateTime from a string, so runs the provided method.
            Assert.AreEqual(secondResult, result2);
        }
コード例 #11
0
ファイル: DataCacheTest.cs プロジェクト: maduhu/Q42.WinRT
        public async Task ClearInvalidCache()
        {
            //Clear the cache
            await DataCache.ClearAll();

            var result1 = await DataCache.GetAsync("test1", () => LongRunningOperation("result1"), DateTime.Now.AddDays(-1));

            var result2 = await DataCache.GetAsync("test2", () => LongRunningOperation("result2"));

            await DataCache.ClearInvalid();


            var result1_new = await DataCache.GetAsync("test1", () => LongRunningOperation("result1_new"));

            var result2_new = await DataCache.GetAsync("test2", () => LongRunningOperation("result2_new"));

            Assert.AreEqual("result1_new", result1_new); //Not from cache
            Assert.AreEqual("result2", result2_new);     //From cache
        }
コード例 #12
0
ファイル: DataCacheTest.cs プロジェクト: sanjayasl/Q42.WinRT
        public async Task ClearCacheMaxSizeTest()
        {
            //Clear the cache
            await DataCache.ClearAll();

            await DataCache.Set("first", "first result");

            await DataCache.Set("second", "second result");

            await DataCache.Clear(100);

            //First is gone
            var firstResult = await DataCache.GetFromCache <string>("first");

            Assert.IsNull(firstResult);

            //Second is still available
            var secondResult = await DataCache.GetFromCache <string>("second");

            Assert.AreEqual("second result", secondResult);
        }
コード例 #13
0
 /// <summary>
 /// Clears the DataCache
 /// </summary>
 private void ClearCacheAction()
 {
     DataCache.ClearAll();
 }
コード例 #14
0
 public static Task ClearCache()
 {
     return(DataCache.ClearAll());
 }