Skip to content

Commit 376c3cc

Browse files
Do not declare cacheKey variable to avoid confusion
1 parent 14cfb8a commit 376c3cc

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,22 @@ private async Task ProcessRequestAsync(
268268
ImageContext imageContext,
269269
CommandCollection commands)
270270
{
271-
// Create a cache key and hash
272-
string cacheKey = this.cacheKey.Create(context, commands);
273-
string cacheHash = this.cacheHash.Create(cacheKey, this.options.CachedNameLength);
271+
// Create a hashed cache key
272+
string key = this.cacheHash.Create(
273+
this.cacheKey.Create(context, commands),
274+
this.options.CachedNameLength);
274275

275276
// Check the cache, if present, not out of date and not requiring an update
276277
// we'll simply serve the file from there.
277278
ImageWorkerResult readResult = default;
278-
using (await this.asyncKeyLock.ReaderLockAsync(cacheHash))
279+
using (await this.asyncKeyLock.ReaderLockAsync(key))
279280
{
280-
readResult = await this.IsNewOrUpdatedAsync(sourceImageResolver, cacheHash);
281+
readResult = await this.IsNewOrUpdatedAsync(sourceImageResolver, key);
281282
}
282283

283284
if (!readResult.IsNewOrUpdated)
284285
{
285-
await this.SendResponseAsync(imageContext, cacheHash, readResult.CacheImageMetadata, readResult.Resolver, null);
286+
await this.SendResponseAsync(imageContext, key, readResult.CacheImageMetadata, readResult.Resolver, null);
286287
return;
287288
}
288289

@@ -294,7 +295,7 @@ private async Task ProcessRequestAsync(
294295
RecyclableMemoryStream outStream = null;
295296
try
296297
{
297-
Task<IDisposable> takeLockTask = this.asyncKeyLock.WriterLockAsync(cacheHash);
298+
Task<IDisposable> takeLockTask = this.asyncKeyLock.WriterLockAsync(key);
298299
bool lockWasAlreadyHeld = takeLockTask.Status != TaskStatus.RanToCompletion;
299300
using (await takeLockTask)
300301
{
@@ -303,7 +304,7 @@ private async Task ProcessRequestAsync(
303304
// the cache one more time
304305
if (lockWasAlreadyHeld)
305306
{
306-
readResult = await this.IsNewOrUpdatedAsync(sourceImageResolver, cacheHash);
307+
readResult = await this.IsNewOrUpdatedAsync(sourceImageResolver, key);
307308
}
308309

309310
if (readResult.IsNewOrUpdated)
@@ -365,12 +366,12 @@ private async Task ProcessRequestAsync(
365366
outStream.Length);
366367

367368
// Save the image to the cache and send the response to the caller.
368-
await this.cache.SetAsync(cacheHash, outStream, cachedImageMetadata);
369+
await this.cache.SetAsync(key, outStream, cachedImageMetadata);
369370
outStream.Position = 0;
370371

371372
// Remove any resolver from the cache so we always resolve next request
372373
// for the same key.
373-
CacheResolverLru.TryRemove(cacheHash);
374+
CacheResolverLru.TryRemove(key);
374375

375376
readResult = new ImageWorkerResult(cachedImageMetadata, null);
376377
}
@@ -384,7 +385,7 @@ private async Task ProcessRequestAsync(
384385
}
385386
}
386387

387-
await this.SendResponseAsync(imageContext, cacheHash, readResult.CacheImageMetadata, readResult.Resolver, outStream);
388+
await this.SendResponseAsync(imageContext, key, readResult.CacheImageMetadata, readResult.Resolver, outStream);
388389
}
389390
finally
390391
{

0 commit comments

Comments
 (0)