Browse Source

v3.0.0.2

- Fixing diskcache expiration bug


Former-commit-id: 25a8b90f43b3ca87b3e366f6efa6b8bb0a49fbf7
af/merge-core
James South 12 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>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

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

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

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

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

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

@ -142,17 +142,18 @@ namespace ImageProcessor.Web.Caching
/// <summary>
/// Adds an image to the cache.
/// </summary>
/// <param name="lastWriteTimeUtc">
/// The last write time.
/// <param name="creationAndLastWriteDateTimes">
/// The creation and last write times.
/// </param>
internal void AddImageToCache(DateTime lastWriteTimeUtc)
internal void AddImageToCache(Tuple<DateTime, DateTime> creationAndLastWriteDateTimes)
{
string key = Path.GetFileNameWithoutExtension(this.CachedPath);
CachedImage cachedImage = new CachedImage
{
Key = key,
Path = this.CachedPath,
LastWriteTimeUtc = lastWriteTimeUtc
CreationTimeUtc = creationAndLastWriteDateTimes.Item1,
LastWriteTimeUtc = creationAndLastWriteDateTimes.Item2
};
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
// 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);
isUpdated = true;
@ -207,7 +208,7 @@ namespace ImageProcessor.Web.Caching
// 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.
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);
isUpdated = true;
@ -250,7 +251,7 @@ namespace ImageProcessor.Web.Caching
/// <returns>
/// The <see cref="T:System.DateTime"/> set to the last write time of the file.
/// </returns>
internal async Task<DateTime> SetCachedLastWriteTimeAsync()
internal async Task<Tuple<DateTime, DateTime>> SetCachedLastWriteTimeAsync()
{
// Create Action delegate for SetCachedLastWriteTime.
return await TaskHelpers.Run(() => this.SetCachedLastWriteTime());
@ -278,15 +279,18 @@ namespace ImageProcessor.Web.Caching
/// <returns>
/// The <see cref="T:System.DateTime"/> of the original and cached file.
/// </returns>
private DateTime SetCachedLastWriteTime()
private Tuple<DateTime, DateTime> SetCachedLastWriteTime()
{
FileInfo cachedFileInfo = new FileInfo(this.CachedPath);
DateTime creationTime = DateTime.MinValue.ToUniversalTime();
DateTime lastWriteTime = DateTime.MinValue.ToUniversalTime();
if (this.isRemote)
{
if (cachedFileInfo.Exists)
{
creationTime = cachedFileInfo.CreationTimeUtc;
lastWriteTime = cachedFileInfo.LastWriteTimeUtc;
}
}
@ -297,13 +301,14 @@ namespace ImageProcessor.Web.Caching
if (imageFileInfo.Exists && cachedFileInfo.Exists)
{
DateTime dateTime = imageFileInfo.LastWriteTimeUtc;
creationTime = cachedFileInfo.CreationTimeUtc;
cachedFileInfo.LastWriteTimeUtc = dateTime;
lastWriteTime = dateTime;
}
}
return lastWriteTime;
return new Tuple<DateTime, DateTime>(creationTime, lastWriteTime);
}
/// <summary>
@ -316,7 +321,7 @@ namespace ImageProcessor.Web.Caching
{
// ReSharper disable once AssignNullToNotNullAttribute
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();
foreach (FileInfo fileInfo in files)

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

@ -300,10 +300,10 @@ namespace ImageProcessor.Web.HttpModules
.AutoProcess().Save(cachedPath);
// 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.
cache.AddImageToCache(dateTime);
cache.AddImageToCache(creationAndLastWriteDateTimes);
// Trim the cache.
await cache.TrimCachedFolderAsync(cachedPath);
@ -315,12 +315,12 @@ namespace ImageProcessor.Web.HttpModules
else
{
imageFactory.Load(fullPath).AutoProcess().Save(cachedPath);
// 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.
cache.AddImageToCache(dateTime);
cache.AddImageToCache(creationAndLastWriteDateTimes);
// Trim the cache.
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
// by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.0.1")]
[assembly: AssemblyFileVersion("3.0.0.1")]
[assembly: AssemblyVersion("3.0.0.2")]
[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>
<appSettings>
<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="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
</appSettings>
<system.web>

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

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

Loading…
Cancel
Save