From d49f87fadaa2281f098742345fb931fd596ca787 Mon Sep 17 00:00:00 2001 From: James South Date: Sun, 17 Aug 2014 23:09:01 +0100 Subject: [PATCH] Removing unnecessary async methods Former-commit-id: 0391e03573f196b24788af269041fdd63da6f4e5 --- .../Caching/CacheIndexer.cs | 55 ++++++------------- src/ImageProcessor.Web/Caching/DiskCache.cs | 4 +- .../HttpModules/ImageProcessingModule.cs | 2 +- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/src/ImageProcessor.Web/Caching/CacheIndexer.cs b/src/ImageProcessor.Web/Caching/CacheIndexer.cs index 3fee08f60..e69e65c59 100644 --- a/src/ImageProcessor.Web/Caching/CacheIndexer.cs +++ b/src/ImageProcessor.Web/Caching/CacheIndexer.cs @@ -10,13 +10,9 @@ namespace ImageProcessor.Web.Caching { - #region Using using System.Collections.Generic; using System.IO; using System.Runtime.Caching; - using System.Threading.Tasks; - using ImageProcessor.Web.Helpers; - #endregion /// /// Represents an in memory collection of keys and values whose operations are concurrent. @@ -34,19 +30,32 @@ namespace ImageProcessor.Web.Caching /// The matching the given key if the contains an element with /// the specified key; otherwise, null. /// - public static async Task GetValueAsync(string cachedPath) + public static CachedImage GetValue(string cachedPath) { string key = Path.GetFileNameWithoutExtension(cachedPath); CachedImage cachedImage = (CachedImage)MemCache.GetItem(key); if (cachedImage == null) { - cachedImage = await Task.Run(() => GetCachedImage(cachedPath)); + // FileInfo is thread safe. + FileInfo fileInfo = new FileInfo(cachedPath); - if (cachedImage != null) + if (!fileInfo.Exists) { - Add(cachedImage); + return null; } + + // Pull the latest info. + fileInfo.Refresh(); + + cachedImage = new CachedImage + { + Key = Path.GetFileNameWithoutExtension(cachedPath), + Path = cachedPath, + CreationTimeUtc = fileInfo.CreationTimeUtc + }; + + Add(cachedImage); } return cachedImage; @@ -87,35 +96,5 @@ namespace ImageProcessor.Web.Caching return cachedImage; } #endregion - - /// - /// Creates a new cached image from the cache instance on disk. - /// - /// - /// The cache path. - /// - /// - /// The from the cache instance on disk. - /// - private static CachedImage GetCachedImage(string cachePath) - { - // FileInfo is thread safe. - FileInfo fileInfo = new FileInfo(cachePath); - - if (!fileInfo.Exists) - { - return null; - } - - // Pull the latest info. - fileInfo.Refresh(); - - return new CachedImage - { - Key = Path.GetFileNameWithoutExtension(cachePath), - Path = cachePath, - CreationTimeUtc = fileInfo.CreationTimeUtc - }; - } } } \ No newline at end of file diff --git a/src/ImageProcessor.Web/Caching/DiskCache.cs b/src/ImageProcessor.Web/Caching/DiskCache.cs index 5acfc95ca..8fb69810b 100644 --- a/src/ImageProcessor.Web/Caching/DiskCache.cs +++ b/src/ImageProcessor.Web/Caching/DiskCache.cs @@ -159,10 +159,10 @@ namespace ImageProcessor.Web.Caching /// /// True if the the original file is new or has been updated; otherwise, false. /// - internal async Task IsNewOrUpdatedFileAsync(string cachedPath) + internal bool IsNewOrUpdatedFile(string cachedPath) { bool isUpdated = false; - CachedImage cachedImage = await CacheIndexer.GetValueAsync(cachedPath); + CachedImage cachedImage = CacheIndexer.GetValue(cachedPath); if (cachedImage == null) { diff --git a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs index 51adccf41..e9eeb56ab 100644 --- a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs @@ -386,7 +386,7 @@ namespace ImageProcessor.Web.HttpModules if (isAllowed) { // Is the file new or updated? - bool isNewOrUpdated = await cache.IsNewOrUpdatedFileAsync(cachedPath); + bool isNewOrUpdated = cache.IsNewOrUpdatedFile(cachedPath); // Only process if the file has been updated. if (isNewOrUpdated)