Browse Source

Cleanup now searches from parent directory

Former-commit-id: 7f08acb1b3a8cb53fcb1501d00703c73d061cfa3
af/merge-core
James South 12 years ago
parent
commit
84607a8533
  1. 48
      src/ImageProcessor.Web/NET45/Caching/DiskCache.cs

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

@ -268,7 +268,7 @@ namespace ImageProcessor.Web.Caching
/// </returns>
internal async Task TrimCachedFolderAsync(string path)
{
await TaskHelpers.Run(() => this.TrimCachedFolder(path));
await TaskHelpers.Run(() => this.TrimCachedFolders(path));
}
#endregion
@ -317,34 +317,40 @@ namespace ImageProcessor.Web.Caching
/// <param name="path">
/// The path to the folder.
/// </param>
private void TrimCachedFolder(string path)
private void TrimCachedFolders(string path)
{
// ReSharper disable once AssignNullToNotNullAttribute
DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(path));
IEnumerable<FileInfo> files = directoryInfo.EnumerateFiles().OrderBy(f => f.CreationTimeUtc);
int count = files.Count();
DirectoryInfo parentDirectoryInfo = directoryInfo.Parent;
foreach (FileInfo fileInfo in files)
// ReSharper disable once PossibleNullReferenceException
foreach (DirectoryInfo enumerateDirectory in parentDirectoryInfo.EnumerateDirectories())
{
try
IEnumerable<FileInfo> files = enumerateDirectory.EnumerateFiles().OrderBy(f => f.CreationTimeUtc);
int count = files.Count();
foreach (FileInfo fileInfo in files)
{
// If the group count is equal to the max count minus 1 then we know we
// have reduced the number of items below the maximum allowed.
// We'll cleanup any orphaned expired files though.
if (!this.IsExpired(fileInfo.CreationTimeUtc) && count <= MaxFilesCount - 1)
try
{
break;
}
// If the group count is equal to the max count minus 1 then we know we
// have reduced the number of items below the maximum allowed.
// We'll cleanup any orphaned expired files though.
if (!this.IsExpired(fileInfo.CreationTimeUtc) && count <= MaxFilesCount - 1)
{
break;
}
// Remove from the cache and delete each CachedImage.
CacheIndexer.Remove(fileInfo.Name);
fileInfo.Delete();
count -= 1;
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// Do nothing; skip to the next file.
// Remove from the cache and delete each CachedImage.
CacheIndexer.Remove(fileInfo.Name);
fileInfo.Delete();
count -= 1;
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// Do nothing; skip to the next file.
}
}
}
}

Loading…
Cancel
Save