Skip to content

Commit b91e3b6

Browse files
Fix cache resolver
1 parent 4311f3d commit b91e3b6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/ImageSharp.Web/Resolvers/PhysicalFileSystemCacheResolver.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.IO;
5+
using System.Runtime.CompilerServices;
56
using System.Threading.Tasks;
67
using SixLabors.ImageSharp.Web.Caching;
78

@@ -33,7 +34,11 @@ public PhysicalFileSystemCacheResolver(FileInfo metaFileInfo, FormatUtilities fo
3334
public async Task<ImageCacheMetadata> GetMetaDataAsync()
3435
{
3536
using Stream stream = OpenFileStream(this.metaFileInfo.FullName);
36-
this.metadata = await ImageCacheMetadata.ReadAsync(stream);
37+
if (this.metadata == default)
38+
{
39+
this.metadata = await ImageCacheMetadata.ReadAsync(stream);
40+
}
41+
3742
return this.metadata;
3843
}
3944

@@ -47,11 +52,12 @@ public Task<Stream> OpenReadAsync()
4752
return Task.FromResult(OpenFileStream(path));
4853
}
4954

55+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5056
private static Stream OpenFileStream(string path)
5157
{
5258
// We are setting buffer size to 1 to prevent FileStream from allocating it's internal buffer
5359
// 0 causes constructor to throw
54-
int bufferSize = 1;
60+
const int bufferSize = 1;
5561
return new FileStream(
5662
path,
5763
FileMode.Open,

0 commit comments

Comments
 (0)