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); }
public async Task DeleteNotExistingCacheKeyTest() { //Clear the cache await DataCache.ClearAll(); await DataCache.Delete("not_exist"); }
private async void ClearCacheButton_OnClick(object sender, RoutedEventArgs e) { ViewModel.IsLoading = true; await DataCache.ClearAll(); ViewModel.IsLoading = false; MessageBox.Show("Web data cache cleared."); }
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); }
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); }
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); }
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 }
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); }
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 }
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); }
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 }
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); }
/// <summary> /// Clears the DataCache /// </summary> private void ClearCacheAction() { DataCache.ClearAll(); }
public static Task ClearCache() { return(DataCache.ClearAll()); }