99using System . IO ;
1010using System . Linq ;
1111using System . Text ;
12- using System . Threading ;
1312using System . Threading . Tasks ;
1413using Microsoft . AspNetCore . Http ;
1514using Microsoft . Extensions . Logging ;
@@ -33,25 +32,25 @@ public class ImageSharpMiddleware
3332 /// The write worker used for limiting identical requests.
3433 /// </summary>
3534 private static readonly ConcurrentDictionary < string , Task < ImageWorkerResult > > WriteWorkers
36- = new ConcurrentDictionary < string , Task < ImageWorkerResult > > ( StringComparer . OrdinalIgnoreCase ) ;
35+ = new ( StringComparer . OrdinalIgnoreCase ) ;
3736
3837 /// <summary>
3938 /// The read worker used for limiting identical requests.
4039 /// </summary>
4140 private static readonly ConcurrentDictionary < string , Task < ImageWorkerResult > > ReadWorkers
42- = new ConcurrentDictionary < string , Task < ImageWorkerResult > > ( StringComparer . OrdinalIgnoreCase ) ;
41+ = new ( StringComparer . OrdinalIgnoreCase ) ;
4342
4443 /// <summary>
4544 /// Used to temporarily store source metadata reads to reduce the overhead of cache lookups.
4645 /// </summary>
4746 private static readonly ConcurrentTLruCache < string , ImageMetadata > SourceMetadataLru
48- = new ConcurrentTLruCache < string , ImageMetadata > ( 1024 , TimeSpan . FromMinutes ( 5 ) ) ;
47+ = new ( 1024 , TimeSpan . FromMinutes ( 5 ) ) ;
4948
5049 /// <summary>
5150 /// Used to temporarily store cache resolver reads to reduce the overhead of cache lookups.
5251 /// </summary>
53- private static readonly ConcurrentTLruCache < string , ValueTuple < IImageCacheResolver , ImageCacheMetadata > > CacheResolverLru
54- = new ConcurrentTLruCache < string , ValueTuple < IImageCacheResolver , ImageCacheMetadata > > ( 1024 , TimeSpan . FromMinutes ( 5 ) ) ;
52+ private static readonly ConcurrentTLruCache < string , ( IImageCacheResolver , ImageCacheMetadata ) > CacheResolverLru
53+ = new ( 1024 , TimeSpan . FromMinutes ( 5 ) ) ;
5554
5655 /// <summary>
5756 /// The function processing the Http request.
@@ -268,7 +267,7 @@ private async Task ProcessRequestAsync(
268267 }
269268
270269 // Not cached, or is updated? Let's get it from the image resolver.
271- var sourceImageMetadata = readResult . SourceImageMetadata ;
270+ ImageMetadata sourceImageMetadata = readResult . SourceImageMetadata ;
272271
273272 // Enter an asynchronous write worker which prevents multiple writes and delays any reads for the same request.
274273 // This reduces the overheads of unnecessary processing.
@@ -494,7 +493,7 @@ private async Task SendResponseAsync(
494493 this . logger . LogImageServed ( imageContext . GetDisplayUrl ( ) , key ) ;
495494
496495 // When stream is null we're sending from the cache.
497- using ( var stream = await cacheResolver . OpenReadAsync ( ) )
496+ using ( Stream stream = await cacheResolver . OpenReadAsync ( ) )
498497 {
499498 await imageContext . SendAsync ( stream , metadata ) ;
500499 }
0 commit comments