Skip to content

Commit 94cdcc5

Browse files
Remove usage of IFileProvider in IImageCache
1 parent c99f07c commit 94cdcc5

2 files changed

Lines changed: 5 additions & 17 deletions

File tree

src/ImageSharp.Web/Caching/PhysicalFileSystemCache.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Runtime.InteropServices;
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Hosting;
10-
using Microsoft.Extensions.FileProviders;
1110
using Microsoft.Extensions.Options;
1211
using SixLabors.ImageSharp.Web.Resolvers;
1312

@@ -28,11 +27,6 @@ public class PhysicalFileSystemCache : IImageCache
2827
/// </summary>
2928
private readonly int cacheFolderDepth;
3029

31-
/// <summary>
32-
/// The file provider abstraction.
33-
/// </summary>
34-
private readonly IFileProvider fileProvider;
35-
3630
/// <summary>
3731
/// Contains various format helper methods based on the current configuration.
3832
/// </summary>
@@ -54,18 +48,13 @@ public PhysicalFileSystemCache(
5448
FormatUtilities formatUtilities)
5549
{
5650
Guard.NotNull(environment, nameof(environment));
57-
Guard.NotNull(options, nameof(options));
5851
Guard.NotNullOrWhiteSpace(environment.WebRootPath, nameof(environment.WebRootPath));
5952

6053
// Allow configuration of the cache without having to register everything
6154
PhysicalFileSystemCacheOptions cacheOptions = options != null ? options.Value : new();
6255
this.cacheRootPath = GetCacheRoot(cacheOptions, environment.WebRootPath, environment.ContentRootPath);
6356
this.cacheFolderDepth = (int)cacheOptions.CacheFolderDepth;
6457

65-
// Ensure cache directory is created before initializing the file provider
66-
Directory.CreateDirectory(this.cacheRootPath);
67-
68-
this.fileProvider = new PhysicalFileProvider(this.cacheRootPath);
6958
this.formatUtilities = formatUtilities;
7059
}
7160

@@ -92,7 +81,7 @@ public Task<IImageCacheResolver> GetAsync(string key)
9281
{
9382
string path = ToFilePath(key, this.cacheFolderDepth);
9483

95-
IFileInfo metaFileInfo = this.fileProvider.GetFileInfo(this.ToMetaDataFilePath(path));
84+
var metaFileInfo = new FileInfo(this.ToMetaDataFilePath(path));
9685
if (!metaFileInfo.Exists)
9786
{
9887
return Task.FromResult<IImageCacheResolver>(null);

src/ImageSharp.Web/Caching/PhysicalFileSystemCacheResolver.cs renamed to src/ImageSharp.Web/Resolvers/PhysicalFileSystemCacheResolver.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.IO;
55
using System.Threading.Tasks;
6-
using Microsoft.Extensions.FileProviders;
76
using SixLabors.ImageSharp.Web.Caching;
87

98
namespace SixLabors.ImageSharp.Web.Resolvers
@@ -13,7 +12,7 @@ namespace SixLabors.ImageSharp.Web.Resolvers
1312
/// </summary>
1413
public class PhysicalFileSystemCacheResolver : IImageCacheResolver
1514
{
16-
private readonly IFileInfo metaFileInfo;
15+
private readonly FileInfo metaFileInfo;
1716
private readonly FormatUtilities formatUtilities;
1817
private ImageCacheMetadata metadata;
1918

@@ -24,7 +23,7 @@ public class PhysicalFileSystemCacheResolver : IImageCacheResolver
2423
/// <param name="formatUtilities">
2524
/// Contains various format helper methods based on the current configuration.
2625
/// </param>
27-
public PhysicalFileSystemCacheResolver(IFileInfo metaFileInfo, FormatUtilities formatUtilities)
26+
public PhysicalFileSystemCacheResolver(FileInfo metaFileInfo, FormatUtilities formatUtilities)
2827
{
2928
this.metaFileInfo = metaFileInfo;
3029
this.formatUtilities = formatUtilities;
@@ -33,7 +32,7 @@ public PhysicalFileSystemCacheResolver(IFileInfo metaFileInfo, FormatUtilities f
3332
/// <inheritdoc/>
3433
public async Task<ImageCacheMetadata> GetMetaDataAsync()
3534
{
36-
using Stream stream = this.metaFileInfo.CreateReadStream();
35+
using Stream stream = this.metaFileInfo.OpenRead();
3736
this.metadata = await ImageCacheMetadata.ReadAsync(stream);
3837
return this.metadata;
3938
}
@@ -42,7 +41,7 @@ public async Task<ImageCacheMetadata> GetMetaDataAsync()
4241
public Task<Stream> OpenReadAsync()
4342
{
4443
string path = Path.ChangeExtension(
45-
this.metaFileInfo.PhysicalPath,
44+
this.metaFileInfo.FullName,
4645
this.formatUtilities.GetExtensionFromContentType(this.metadata.ContentType));
4746

4847
return Task.FromResult<Stream>(File.OpenRead(path));

0 commit comments

Comments
 (0)