Skip to content

Commit ddb4653

Browse files
Rename CachedNameLength to CacheHashLength
1 parent 99b9270 commit ddb4653

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

samples/ImageSharp.Web.Sample/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private void ConfigureDefaultServicesAndCustomOptions(IServiceCollection service
8888
options.Configuration = Configuration.Default;
8989
options.BrowserMaxAge = TimeSpan.FromDays(7);
9090
options.CacheMaxAge = TimeSpan.FromDays(365);
91-
options.CachedNameLength = 8;
91+
options.CacheHashLength = 8;
9292
options.OnParseCommandsAsync = _ => Task.CompletedTask;
9393
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
9494
options.OnProcessedAsync = _ => Task.CompletedTask;
@@ -111,7 +111,7 @@ private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services
111111
options.Configuration = Configuration.Default;
112112
options.BrowserMaxAge = TimeSpan.FromDays(7);
113113
options.CacheMaxAge = TimeSpan.FromDays(365);
114-
options.CachedNameLength = 8;
114+
options.CacheHashLength = 8;
115115
options.OnParseCommandsAsync = _ => Task.CompletedTask;
116116
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
117117
options.OnProcessedAsync = _ => Task.CompletedTask;

src/ImageSharp.Web/Caching/PhysicalFileSystemCache.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public class PhysicalFileSystemCache : IImageCache
2525
private readonly string cacheRootPath;
2626

2727
/// <summary>
28-
/// The length of the filename to use (minus the extension) when storing images in the image cache.
28+
/// The depth of the nested cache folders structure to store the images.
2929
/// </summary>
30-
private readonly int cachedNameLength;
30+
private readonly int cacheFolderDepth;
3131

3232
/// <summary>
3333
/// The file provider abstraction.
@@ -80,7 +80,7 @@ public PhysicalFileSystemCache(
8080

8181
this.fileProvider = new PhysicalFileProvider(this.cacheRootPath);
8282
this.options = options.Value;
83-
this.cachedNameLength = (int)this.options.CachedNameLength;
83+
this.cacheFolderDepth = (int)this.options.CacheHashLength;
8484
this.formatUtilities = formatUtilities;
8585
}
8686

@@ -105,7 +105,7 @@ internal static string GetCacheRoot(PhysicalFileSystemCacheOptions cacheOptions,
105105
/// <inheritdoc/>
106106
public Task<IImageCacheResolver> GetAsync(string key)
107107
{
108-
string path = ToFilePath(key, this.cachedNameLength);
108+
string path = ToFilePath(key, this.cacheFolderDepth);
109109

110110
IFileInfo metaFileInfo = this.fileProvider.GetFileInfo(this.ToMetaDataFilePath(path));
111111
if (!metaFileInfo.Exists)
@@ -119,7 +119,7 @@ public Task<IImageCacheResolver> GetAsync(string key)
119119
/// <inheritdoc/>
120120
public async Task SetAsync(string key, Stream stream, ImageCacheMetadata metadata)
121121
{
122-
string path = Path.Combine(this.cacheRootPath, ToFilePath(key, this.cachedNameLength));
122+
string path = Path.Combine(this.cacheRootPath, ToFilePath(key, this.cacheFolderDepth));
123123
string imagePath = this.ToImageFilePath(path, metadata);
124124
string metaPath = this.ToMetaDataFilePath(path);
125125
string directory = Path.GetDirectoryName(path);
@@ -162,13 +162,13 @@ private string ToImageFilePath(string path, in ImageCacheMetadata metaData)
162162
/// Converts the key into a nested file path.
163163
/// </summary>
164164
/// <param name="key">The cache key.</param>
165-
/// <param name="cachedNameLength">The length of the cached file name minus the extension.</param>
165+
/// <param name="cacheFolderDepth">The depth of the nested cache folders structure to store the images.</param>
166166
/// <returns>The <see cref="string"/>.</returns>
167167
[MethodImpl(MethodImplOptions.AggressiveInlining)]
168-
internal static unsafe string ToFilePath(string key, int cachedNameLength)
168+
internal static unsafe string ToFilePath(string key, int cacheFolderDepth)
169169
{
170170
// Each key substring char + separator + key
171-
int length = (cachedNameLength * 2) + key.Length;
171+
int length = (cacheFolderDepth * 2) + key.Length;
172172
fixed (char* keyPtr = key)
173173
{
174174
return string.Create(length, (Ptr: (IntPtr)keyPtr, key.Length), (chars, args) =>
@@ -179,7 +179,7 @@ internal static unsafe string ToFilePath(string key, int cachedNameLength)
179179
ref char charRef = ref MemoryMarshal.GetReference(chars);
180180

181181
int index = 0;
182-
for (int i = 0; i < cachedNameLength; i++)
182+
for (int i = 0; i < cacheFolderDepth; i++)
183183
{
184184
Unsafe.Add(ref charRef, index++) = Unsafe.Add(ref keyRef, i);
185185
Unsafe.Add(ref charRef, index++) = separator;

src/ImageSharp.Web/Caching/SHA256CacheHash.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed class SHA256CacheHash : ICacheHash
2525
public SHA256CacheHash(IOptions<ImageSharpMiddlewareOptions> options)
2626
{
2727
Guard.NotNull(options, nameof(options));
28-
Guard.MustBeBetweenOrEqualTo<uint>(options.Value.CachedNameLength, 2, 64, nameof(options.Value.CachedNameLength));
28+
Guard.MustBeBetweenOrEqualTo<uint>(options.Value.CacheHashLength, 2, 64, nameof(options.Value.CacheHashLength));
2929
}
3030

3131
/// <inheritdoc/>

src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private async Task ProcessRequestAsync(
271271
// Create a hashed cache key
272272
string key = this.cacheHash.Create(
273273
this.cacheKey.Create(context, commands),
274-
this.options.CachedNameLength);
274+
this.options.CacheHashLength);
275275

276276
// Check the cache, if present, not out of date and not requiring an update
277277
// we'll simply serve the file from there.

src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public class ImageSharpMiddlewareOptions
8888
/// Gets or sets the length of the filename to use (minus the extension) when storing
8989
/// images in the image cache. Defaults to 12 characters.
9090
/// </summary>
91-
public uint CachedNameLength { get; set; } = 12;
91+
public uint CacheHashLength { get; set; } = 12;
9292

9393
/// <summary>
9494
/// Gets or sets the additional command parsing method that can be used to used to augment commands.

0 commit comments

Comments
 (0)