Beispiel #1
0
        /// <summary>
        /// Removes all images with the specified <see cref="Uri"/>
        /// from disk cache.
        /// </summary>
        /// <param name="imageRequest">
        /// The imageRequest for the image to evict from disk cache.
        /// </param>
        public async Task EvictFromDiskCacheAsync(ImageRequest imageRequest)
        {
            ICacheKey cacheKey = _cacheKeyFactory.GetEncodedCacheKey(imageRequest, null);
            await _mainBufferedDiskCache.Remove(cacheKey).ConfigureAwait(false);

            await _smallImageBufferedDiskCache.Remove(cacheKey).ConfigureAwait(false);
        }
 /// <summary>
 /// Gets the cache key.
 /// </summary>
 protected override Tuple <ICacheKey, int> GetKey(IProducerContext producerContext)
 {
     return(new Tuple <ICacheKey, int>(
                _cacheKeyFactory.GetEncodedCacheKey(
                    producerContext.ImageRequest,
                    producerContext.CallerContext),
                producerContext.LowestPermittedRequestLevel));
 }
        /// <summary>
        /// Gets the file cache path.
        /// </summary>
        /// <param name="uri">The image uri.</param>
        public Task <FileInfo> GetFileCachePath(Uri uri)
        {
            ICacheKey cacheKey = _cacheKeyFactory.GetEncodedCacheKey(
                ImageRequest.FromUri(uri), null);

            Task writeTask = _mainBufferedDiskCache.GetWriteToDiskCacheTask(cacheKey);

            if (writeTask != default(Task))
            {
                return(writeTask.ContinueWith(
                           task =>
                {
                    IBinaryResource resource = ImagePipelineFactory.Instance.GetMainDiskStorageCache().GetResource(cacheKey);
                    return ((FileBinaryResource)resource).File;
                },
                           TaskContinuationOptions.ExecuteSynchronously));
            }
            else
            {
                return(_mainBufferedDiskCache.Contains(cacheKey).ContinueWith(
                           task =>
                {
                    bool fileExists = task.Result;
                    if (fileExists)
                    {
                        IBinaryResource resource = ImagePipelineFactory.Instance.GetMainDiskStorageCache().GetResource(cacheKey);
                        return ((FileBinaryResource)resource).File;
                    }
                    else
                    {
                        return default(FileInfo);
                    }
                },
                           TaskContinuationOptions.ExecuteSynchronously));
            }
        }