public void TearDown() { try { Cache?.Clear(); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body #pragma warning disable CC0004 // Catch block cannot be empty catch { } #pragma warning restore CC0004 // Catch block cannot be empty #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body finally { Cache = null; } }
public void SetUp() { Cache = new MemoryCache(new MemoryCacheSettings()); Cache.Clear(); }
public async virtual Task <bool> TryLoadFromMemoryCacheAsync() { try { if (Parameters.Preload && Parameters.CacheType.HasValue && (Parameters.CacheType.Value == CacheType.Disk || Parameters.CacheType.Value == CacheType.None)) { return(false); } ThrowIfCancellationRequested(); var isFadeAnimationEnabledForCached = Parameters.FadeAnimationForCachedImagesEnabled ?? Configuration.FadeAnimationForCachedImages; var result = await TryLoadFromMemoryCacheAsync(Key, true, isFadeAnimationEnabledForCached, false).ConfigureAwait(false); if (result) { Logger.Debug(string.Format("Image loaded from cache: {0}", Key)); IsCompleted = true; if (Configuration.ExecuteCallbacksOnUIThread && (Parameters?.OnSuccess != null || Parameters?.OnFinish != null)) { await MainThreadDispatcher.PostAsync(() => { Parameters?.OnSuccess?.Invoke(ImageInformation, LoadingResult.MemoryCache); Parameters?.OnFinish?.Invoke(this); }).ConfigureAwait(false); } else { Parameters?.OnSuccess?.Invoke(ImageInformation, LoadingResult.MemoryCache); Parameters?.OnFinish?.Invoke(this); } } else { ThrowIfCancellationRequested(); // Loading placeholder if enabled if (!_isLoadingPlaceholderLoaded && !string.IsNullOrWhiteSpace(Parameters.LoadingPlaceholderPath)) { await ShowPlaceholder(Parameters.LoadingPlaceholderPath, KeyForLoadingPlaceholder, Parameters.LoadingPlaceholderSource, true).ConfigureAwait(false); } } return(result); } catch (Exception ex) { if (Configuration.ClearMemoryCacheOnOutOfMemory && ex is OutOfMemoryException) { MemoryCache.Clear(); } if (ex is OperationCanceledException) { if (Configuration.VerboseLoadingCancelledLogging) { Logger.Debug(string.Format("Image loading cancelled: {0}", Key)); } } else { Logger.Error(string.Format("Image loading failed: {0}", Key), ex); if (Configuration.ExecuteCallbacksOnUIThread && Parameters?.OnError != null) { await MainThreadDispatcher.PostAsync(() => { Parameters?.OnError?.Invoke(ex); }).ConfigureAwait(false); } else { Parameters?.OnError?.Invoke(ex); } } } return(false); }
/// <inheritdoc /> public void ClearCache() { MemoryCache.Clear(); }
public async Task RunAsync() { LoadingResult loadingResult = LoadingResult.Failed; bool success = false; try { // LOAD IMAGE if (!(await TryLoadFromMemoryCacheAsync().ConfigureAwait(false))) { Logger.Debug(string.Format("Generating/retrieving image: {0}", Key)); var resolver = Parameters.CustomDataResolver ?? DataResolverFactory.GetResolver(Parameters.Path, Parameters.Source, Parameters, Configuration); resolver = new WrappedDataResolver(resolver); var imageData = await resolver.Resolve(Parameters.Path, Parameters, CancellationTokenSource.Token).ConfigureAwait(false); loadingResult = imageData.Item2; using (imageData.Item1) { ImageInformation = imageData.Item3; ImageInformation.SetKey(Key, Parameters.CustomCacheKey); ImageInformation.SetPath(Parameters.Path); ThrowIfCancellationRequested(); // Preload if (Parameters.Preload && Parameters.CacheType.HasValue && Parameters.CacheType.Value == CacheType.Disk) { if (loadingResult == LoadingResult.Internet) { Logger?.Debug(string.Format("DownloadOnly success: {0}", Key)); } success = true; return; } ThrowIfCancellationRequested(); var image = await GenerateImageAsync(Parameters.Path, Parameters.Source, imageData.Item1, imageData.Item3, true, false).ConfigureAwait(false); ThrowIfCancellationRequested(); try { BeforeLoading(image, false); if (image != default(TImageContainer) && CanUseMemoryCache) { MemoryCache.Add(Key, imageData.Item3, image); } ThrowIfCancellationRequested(); bool isFadeAnimationEnabled = Parameters.FadeAnimationEnabled ?? Configuration.FadeAnimationEnabled; await SetTargetAsync(image, isFadeAnimationEnabled).ConfigureAwait(false); } finally { AfterLoading(image, false); } } } success = true; } catch (Exception ex) { if (ex is OperationCanceledException || ex is ObjectDisposedException) { if (Configuration.VerboseLoadingCancelledLogging) { Logger.Debug(string.Format("Image loading cancelled: {0}", Key)); } } else { if (_clearCacheOnOutOfMemory && ex is OutOfMemoryException) { MemoryCache.Clear(); } Logger.Error(string.Format("Image loading failed: {0}", Key), ex); if (Configuration.ExecuteCallbacksOnUIThread && Parameters?.OnError != null) { await MainThreadDispatcher.PostAsync(() => { Parameters?.OnError?.Invoke(ex); }).ConfigureAwait(false); } else { Parameters?.OnError?.Invoke(ex); } try { // Error placeholder if enabled if (!Parameters.Preload && !string.IsNullOrWhiteSpace(Parameters.ErrorPlaceholderPath)) { await ShowPlaceholder(Parameters.ErrorPlaceholderPath, KeyForErrorPlaceholder, Parameters.ErrorPlaceholderSource, false).ConfigureAwait(false); } } catch (Exception ex2) { if (!(ex2 is OperationCanceledException)) { Logger.Error(string.Format("Image loading failed: {0}", Key), ex); } } } } finally { try { if (CancellationTokenSource?.IsCancellationRequested == false) { CancellationTokenSource.Cancel(); } } catch (Exception) { } IsCompleted = true; using (Parameters) { if (Configuration.ExecuteCallbacksOnUIThread && Parameters?.OnFinish != null) { await MainThreadDispatcher.PostAsync(() => { if (success) { Parameters?.OnSuccess?.Invoke(ImageInformation, loadingResult); } Parameters?.OnFinish?.Invoke(this); }).ConfigureAwait(false); } else { if (success) { Parameters?.OnSuccess?.Invoke(ImageInformation, loadingResult); } Parameters?.OnFinish?.Invoke(this); } ImageService.RemovePendingTask(this); } } }
/// <summary> /// 清理全部会话 /// </summary> public void Clear() { _sessionCache.Clear(); }
public override void ClearCache() { _tileCache.Clear(); _vectorCache.Clear(); }
public void Clear_the_cache() { ICache caching = new MemoryCache(mockLogger); bool clear = caching.Clear(); Assert.IsTrue(clear); }
static DataReaderWrapCache() { Query.CacheCleaners.Enqueue(() => _readerMappings.Clear()); }
public override void ClearCache() { AbortFetch(); _memoryCache.Clear(); }
public void ClearFormulaCache() { executionFormulaCache.Clear(); }