Browse Source

v3.0.0.2

- Fixing diskcache expiration bug


Former-commit-id: 25a8b90f43b3ca87b3e366f6efa6b8bb0a49fbf7
af/merge-core
James South 13 years ago
parent
commit
5be807fb41
  1. 2
      src/ImageProcessor.Tests/ImageProcessor.Tests.csproj
  2. 1
      src/ImageProcessor.Web/NET45/Caching/CacheIndexer.cs
  3. 5
      src/ImageProcessor.Web/NET45/Caching/CachedImage.cs
  4. 25
      src/ImageProcessor.Web/NET45/Caching/DiskCache.cs
  5. 10
      src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
  6. 4
      src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs
  7. BIN
      src/Nuget/ImageProcessor.1.7.1.1.nupkg
  8. 1
      src/Nuget/ImageProcessor.Web.2.3.0.6.nupkg.REMOVED.git-id
  9. BIN
      src/Nuget/ImageProcessor.Web.3.0.0.0.nupkg
  10. BIN
      src/Nuget/ImageProcessor.Web.3.0.0.2.nupkg
  11. 4
      src/TestWebsites/NET45/Test_Website_NET45/Web.config
  12. 30
      src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

2
src/ImageProcessor.Tests/ImageProcessor.Tests.csproj

@ -48,7 +48,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>

1
src/ImageProcessor.Web/NET45/Caching/CacheIndexer.cs

@ -114,6 +114,7 @@ namespace ImageProcessor.Web.Caching
{ {
Key = Path.GetFileNameWithoutExtension(cachePath), Key = Path.GetFileNameWithoutExtension(cachePath),
Path = cachePath, Path = cachePath,
CreationTimeUtc = fileInfo.CreationTimeUtc,
LastWriteTimeUtc = fileInfo.LastWriteTimeUtc LastWriteTimeUtc = fileInfo.LastWriteTimeUtc
}; };
} }

5
src/ImageProcessor.Web/NET45/Caching/CachedImage.cs

@ -29,6 +29,11 @@ namespace ImageProcessor.Web.Caching
/// </summary> /// </summary>
public string Path { get; set; } public string Path { get; set; }
/// <summary>
/// Gets or sets the creation time of the cached image.
/// </summary>
public DateTime CreationTimeUtc { get; set; }
/// <summary> /// <summary>
/// Gets or sets the last write time of the cached image. /// Gets or sets the last write time of the cached image.
/// </summary> /// </summary>

25
src/ImageProcessor.Web/NET45/Caching/DiskCache.cs

@ -142,17 +142,18 @@ namespace ImageProcessor.Web.Caching
/// <summary> /// <summary>
/// Adds an image to the cache. /// Adds an image to the cache.
/// </summary> /// </summary>
/// <param name="lastWriteTimeUtc"> /// <param name="creationAndLastWriteDateTimes">
/// The last write time. /// The creation and last write times.
/// </param> /// </param>
internal void AddImageToCache(DateTime lastWriteTimeUtc) internal void AddImageToCache(Tuple<DateTime, DateTime> creationAndLastWriteDateTimes)
{ {
string key = Path.GetFileNameWithoutExtension(this.CachedPath); string key = Path.GetFileNameWithoutExtension(this.CachedPath);
CachedImage cachedImage = new CachedImage CachedImage cachedImage = new CachedImage
{ {
Key = key, Key = key,
Path = this.CachedPath, Path = this.CachedPath,
LastWriteTimeUtc = lastWriteTimeUtc CreationTimeUtc = creationAndLastWriteDateTimes.Item1,
LastWriteTimeUtc = creationAndLastWriteDateTimes.Item2
}; };
CacheIndexer.Add(cachedImage); CacheIndexer.Add(cachedImage);
@ -178,7 +179,7 @@ namespace ImageProcessor.Web.Caching
{ {
// Can't check the last write time so check to see if the cached image is set to expire // Can't check the last write time so check to see if the cached image is set to expire
// or if the max age is different. // or if the max age is different.
if (cachedImage.LastWriteTimeUtc.AddDays(MaxFileCachedDuration) < DateTime.UtcNow.AddDays(-MaxFileCachedDuration)) if (cachedImage.CreationTimeUtc.AddDays(MaxFileCachedDuration) < DateTime.UtcNow.AddDays(-MaxFileCachedDuration))
{ {
CacheIndexer.Remove(path); CacheIndexer.Remove(path);
isUpdated = true; isUpdated = true;
@ -207,7 +208,7 @@ namespace ImageProcessor.Web.Caching
// Check to see if the last write time is different of whether the // Check to see if the last write time is different of whether the
// cached image is set to expire or if the max age is different. // cached image is set to expire or if the max age is different.
if (!this.RoughDateTimeCompare(imageFileInfo.LastWriteTimeUtc, cachedImage.LastWriteTimeUtc) if (!this.RoughDateTimeCompare(imageFileInfo.LastWriteTimeUtc, cachedImage.LastWriteTimeUtc)
|| cachedImage.LastWriteTimeUtc.AddDays(MaxFileCachedDuration) < DateTime.UtcNow.AddDays(-MaxFileCachedDuration)) || cachedImage.CreationTimeUtc.AddDays(MaxFileCachedDuration) < DateTime.UtcNow.AddDays(-MaxFileCachedDuration))
{ {
CacheIndexer.Remove(path); CacheIndexer.Remove(path);
isUpdated = true; isUpdated = true;
@ -250,7 +251,7 @@ namespace ImageProcessor.Web.Caching
/// <returns> /// <returns>
/// The <see cref="T:System.DateTime"/> set to the last write time of the file. /// The <see cref="T:System.DateTime"/> set to the last write time of the file.
/// </returns> /// </returns>
internal async Task<DateTime> SetCachedLastWriteTimeAsync() internal async Task<Tuple<DateTime, DateTime>> SetCachedLastWriteTimeAsync()
{ {
// Create Action delegate for SetCachedLastWriteTime. // Create Action delegate for SetCachedLastWriteTime.
return await TaskHelpers.Run(() => this.SetCachedLastWriteTime()); return await TaskHelpers.Run(() => this.SetCachedLastWriteTime());
@ -278,15 +279,18 @@ namespace ImageProcessor.Web.Caching
/// <returns> /// <returns>
/// The <see cref="T:System.DateTime"/> of the original and cached file. /// The <see cref="T:System.DateTime"/> of the original and cached file.
/// </returns> /// </returns>
private DateTime SetCachedLastWriteTime() private Tuple<DateTime, DateTime> SetCachedLastWriteTime()
{ {
FileInfo cachedFileInfo = new FileInfo(this.CachedPath); FileInfo cachedFileInfo = new FileInfo(this.CachedPath);
DateTime creationTime = DateTime.MinValue.ToUniversalTime();
DateTime lastWriteTime = DateTime.MinValue.ToUniversalTime(); DateTime lastWriteTime = DateTime.MinValue.ToUniversalTime();
if (this.isRemote) if (this.isRemote)
{ {
if (cachedFileInfo.Exists) if (cachedFileInfo.Exists)
{ {
creationTime = cachedFileInfo.CreationTimeUtc;
lastWriteTime = cachedFileInfo.LastWriteTimeUtc; lastWriteTime = cachedFileInfo.LastWriteTimeUtc;
} }
} }
@ -297,13 +301,14 @@ namespace ImageProcessor.Web.Caching
if (imageFileInfo.Exists && cachedFileInfo.Exists) if (imageFileInfo.Exists && cachedFileInfo.Exists)
{ {
DateTime dateTime = imageFileInfo.LastWriteTimeUtc; DateTime dateTime = imageFileInfo.LastWriteTimeUtc;
creationTime = cachedFileInfo.CreationTimeUtc;
cachedFileInfo.LastWriteTimeUtc = dateTime; cachedFileInfo.LastWriteTimeUtc = dateTime;
lastWriteTime = dateTime; lastWriteTime = dateTime;
} }
} }
return lastWriteTime; return new Tuple<DateTime, DateTime>(creationTime, lastWriteTime);
} }
/// <summary> /// <summary>
@ -316,7 +321,7 @@ namespace ImageProcessor.Web.Caching
{ {
// ReSharper disable once AssignNullToNotNullAttribute // ReSharper disable once AssignNullToNotNullAttribute
DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(path)); DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(path));
IEnumerable<FileInfo> files = directoryInfo.EnumerateFiles().OrderBy(f => f.LastWriteTimeUtc); IEnumerable<FileInfo> files = directoryInfo.EnumerateFiles().OrderBy(f => f.CreationTimeUtc);
int count = files.Count(); int count = files.Count();
foreach (FileInfo fileInfo in files) foreach (FileInfo fileInfo in files)

10
src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs

@ -300,10 +300,10 @@ namespace ImageProcessor.Web.HttpModules
.AutoProcess().Save(cachedPath); .AutoProcess().Save(cachedPath);
// Ensure that the LastWriteTime property of the source and cached file match. // Ensure that the LastWriteTime property of the source and cached file match.
DateTime dateTime = await cache.SetCachedLastWriteTimeAsync(); Tuple<DateTime, DateTime> creationAndLastWriteDateTimes = await cache.SetCachedLastWriteTimeAsync();
// Add to the cache. // Add to the cache.
cache.AddImageToCache(dateTime); cache.AddImageToCache(creationAndLastWriteDateTimes);
// Trim the cache. // Trim the cache.
await cache.TrimCachedFolderAsync(cachedPath); await cache.TrimCachedFolderAsync(cachedPath);
@ -315,12 +315,12 @@ namespace ImageProcessor.Web.HttpModules
else else
{ {
imageFactory.Load(fullPath).AutoProcess().Save(cachedPath); imageFactory.Load(fullPath).AutoProcess().Save(cachedPath);
// Ensure that the LastWriteTime property of the source and cached file match. // Ensure that the LastWriteTime property of the source and cached file match.
DateTime dateTime = await cache.SetCachedLastWriteTimeAsync(); Tuple<DateTime, DateTime> creationAndLastWriteDateTimes = await cache.SetCachedLastWriteTimeAsync();
// Add to the cache. // Add to the cache.
cache.AddImageToCache(dateTime); cache.AddImageToCache(creationAndLastWriteDateTimes);
// Trim the cache. // Trim the cache.
await cache.TrimCachedFolderAsync(cachedPath); await cache.TrimCachedFolderAsync(cachedPath);

4
src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs

@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.0.1")] [assembly: AssemblyVersion("3.0.0.2")]
[assembly: AssemblyFileVersion("3.0.0.1")] [assembly: AssemblyFileVersion("3.0.0.2")]

BIN
src/Nuget/ImageProcessor.1.7.1.1.nupkg

Binary file not shown.

1
src/Nuget/ImageProcessor.Web.2.3.0.6.nupkg.REMOVED.git-id

@ -1 +0,0 @@
7f1cb06ddbb5a91892188c8a18109d8db0f76115

BIN
src/Nuget/ImageProcessor.Web.3.0.0.0.nupkg

Binary file not shown.

BIN
src/Nuget/ImageProcessor.Web.3.0.0.2.nupkg

Binary file not shown.

4
src/TestWebsites/NET45/Test_Website_NET45/Web.config

@ -19,11 +19,11 @@
</imageProcessor> </imageProcessor>
<appSettings> <appSettings>
<add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" /> <add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" /> <add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" /> <add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings> </appSettings>
<system.web> <system.web>

30
src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<processing> <processing>
<plugins> <plugins>
<plugin name="Resize"> <plugin name="Resize">
<settings> <settings>
<setting key="MaxWidth" value="3000"/> <setting key="MaxWidth" value="3000"/>
<setting key="MaxHeight" value="3000"/> <setting key="MaxHeight" value="3000"/>
</settings> </settings>
</plugin> </plugin>
<plugin name="Preset"> <plugin name="Preset">
<settings> <settings>
<!--<setting key="demo" value="width=300&#038;height=150"/>--> <setting key="demo" value="width=300&#038;height=150"/>
</settings> </settings>
</plugin> </plugin>
</plugins> </plugins>
</processing> </processing>

Loading…
Cancel
Save