/// <summary> /// Gets a value indicating whether the image is new or updated in an asynchronous manner. /// </summary> /// <returns> /// The <see cref="Task"/>. /// </returns> public override async Task <bool> IsNewOrUpdatedAsync() { // TODO: Before this check is performed it should be throttled. For example, only perform this check // if the last time it was checked is greater than 5 seconds. This would be much better for perf // if there is a high throughput of image requests. string cachedFileName = await this.CreateCachedFileNameAsync().ConfigureAwait(false); this.CachedPath = CachedImageHelper.GetCachedPath(this.absoluteCachePath, cachedFileName, false, this.FolderDepth); this.virtualCachedFilePath = CachedImageHelper.GetCachedPath(this.virtualCachePath, cachedFileName, true, this.FolderDepth); bool isUpdated = false; CachedImage cachedImage = CacheIndexer.Get(this.CachedPath); if (cachedImage == null) { var info = new FileInfo(this.CachedPath); if (info.Exists) { cachedImage = new CachedImage { Key = Path.GetFileNameWithoutExtension(this.CachedPath), Path = this.CachedPath, CreationTimeUtc = info.LastWriteTimeUtc }; CacheIndexer.Add(cachedImage, this.ImageCacheMaxMinutes); } } if (cachedImage == null) { // Nothing in the cache so we should return true. isUpdated = true; } else { // Check to see if the cached image is set to expire // or a new file with the same name has replaced our current image if (this.IsExpired(cachedImage.CreationTimeUtc) || await this.IsUpdatedAsync(cachedImage.CreationTimeUtc).ConfigureAwait(false)) { CacheIndexer.Remove(this.CachedPath); isUpdated = true; } else { // Set cachedImageCreationTimeUtc so we can sender Last-Modified or ETag header when using Response.TransmitFile() this.cachedImageCreationTimeUtc = cachedImage.CreationTimeUtc; } } return(isUpdated); }
/// <summary> /// Gets a string identifying the cached file name. /// </summary> /// <returns> /// The asynchronous <see cref="Task"/> returning the value. /// </returns> public virtual async Task <string> CreateCachedFileNameAsync() { return(await Task.FromResult(CachedImageHelper.GetCachedImageFileName(this.FullPath, this.Querystring))); }
/// <summary> /// Gets a string identifying the cached file name. /// </summary> /// <returns> /// The asynchronous <see cref="Task"/> returning the value. /// </returns> public virtual Task <string> CreateCachedFileNameAsync() => Task.FromResult(CachedImageHelper.GetCachedImageFileName(this.FullPath, this.Querystring));