Skip to content

Commit 24139de

Browse files
Update sample startup and re-ordered options
1 parent 5eb7a89 commit 24139de

2 files changed

Lines changed: 40 additions & 49 deletions

File tree

samples/ImageSharp.Web.Sample/Startup.cs

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.Extensions.Configuration;
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Hosting;
11-
using Microsoft.Extensions.Options;
1211
using SixLabors.ImageSharp.Web.Caching;
1312
using SixLabors.ImageSharp.Web.Commands;
1413
using SixLabors.ImageSharp.Web.DependencyInjection;
@@ -43,17 +42,17 @@ public void ConfigureServices(IServiceCollection services)
4342
.SetRequestParser<QueryCollectionRequestParser>()
4443
.Configure<PhysicalFileSystemCacheOptions>(options =>
4544
{
45+
options.CacheRootPath = null;
4646
options.CacheFolder = "is-cache";
47+
options.CacheFolderDepth = 8;
4748
})
48-
.SetCache(provider =>
49-
{
50-
return new PhysicalFileSystemCache(
51-
provider.GetRequiredService<IOptions<PhysicalFileSystemCacheOptions>>(),
52-
provider.GetRequiredService<IWebHostEnvironment>(),
53-
provider.GetRequiredService<FormatUtilities>());
54-
})
49+
.SetCache<PhysicalFileSystemCache>()
5550
.SetCacheKey<UriRelativeLowerInvariantCacheKey>()
5651
.SetCacheHash<SHA256CacheHash>()
52+
.Configure<PhysicalFileSystemProviderOptions>(options =>
53+
{
54+
options.ProviderRootPath = null;
55+
})
5756
.AddProvider<PhysicalFileSystemProvider>()
5857
.AddProcessor<ResizeWebProcessor>()
5958
.AddProcessor<FormatWebProcessor>()
@@ -80,18 +79,17 @@ public void ConfigureServices(IServiceCollection services)
8079

8180
private void ConfigureDefaultServicesAndCustomOptions(IServiceCollection services)
8281
{
83-
services.AddImageSharp(
84-
options =>
85-
{
86-
options.Configuration = Configuration.Default;
87-
options.BrowserMaxAge = TimeSpan.FromDays(7);
88-
options.CacheMaxAge = TimeSpan.FromDays(365);
89-
options.CacheHashLength = 8;
90-
options.OnParseCommandsAsync = _ => Task.CompletedTask;
91-
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
92-
options.OnProcessedAsync = _ => Task.CompletedTask;
93-
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
94-
});
82+
services.AddImageSharp(options =>
83+
{
84+
options.Configuration = Configuration.Default;
85+
options.BrowserMaxAge = TimeSpan.FromDays(7);
86+
options.CacheMaxAge = TimeSpan.FromDays(365);
87+
options.CacheHashLength = 8;
88+
options.OnParseCommandsAsync = _ => Task.CompletedTask;
89+
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
90+
options.OnProcessedAsync = _ => Task.CompletedTask;
91+
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
92+
});
9593
}
9694

9795
private void ConfigureCustomServicesAndDefaultOptions(IServiceCollection services)
@@ -103,30 +101,23 @@ private void ConfigureCustomServicesAndDefaultOptions(IServiceCollection service
103101

104102
private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services)
105103
{
106-
services.AddImageSharp(
107-
options =>
108-
{
109-
options.Configuration = Configuration.Default;
110-
options.BrowserMaxAge = TimeSpan.FromDays(7);
111-
options.CacheMaxAge = TimeSpan.FromDays(365);
112-
options.CacheHashLength = 8;
113-
options.OnParseCommandsAsync = _ => Task.CompletedTask;
114-
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
115-
options.OnProcessedAsync = _ => Task.CompletedTask;
116-
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
117-
})
104+
services.AddImageSharp(options =>
105+
{
106+
options.Configuration = Configuration.Default;
107+
options.BrowserMaxAge = TimeSpan.FromDays(7);
108+
options.CacheMaxAge = TimeSpan.FromDays(365);
109+
options.CacheHashLength = 8;
110+
options.OnParseCommandsAsync = _ => Task.CompletedTask;
111+
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
112+
options.OnProcessedAsync = _ => Task.CompletedTask;
113+
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
114+
})
118115
.SetRequestParser<QueryCollectionRequestParser>()
119116
.Configure<PhysicalFileSystemCacheOptions>(options =>
120117
{
121118
options.CacheFolder = "different-cache";
122119
})
123-
.SetCache(provider =>
124-
{
125-
return new PhysicalFileSystemCache(
126-
provider.GetRequiredService<IOptions<PhysicalFileSystemCacheOptions>>(),
127-
provider.GetRequiredService<IWebHostEnvironment>(),
128-
provider.GetRequiredService<FormatUtilities>());
129-
})
120+
.SetCache<PhysicalFileSystemCache>()
130121
.SetCacheKey<UriRelativeLowerInvariantCacheKey>()
131122
.SetCacheHash<SHA256CacheHash>()
132123
.ClearProviders()

src/ImageSharp.Web/Caching/PhysicalFileSystemCacheOptions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ namespace SixLabors.ImageSharp.Web.Caching
88
/// </summary>
99
public class PhysicalFileSystemCacheOptions
1010
{
11-
/// <summary>
12-
/// Gets or sets the cache folder name.
13-
/// </summary>
14-
public string CacheFolder { get; set; } = "is-cache";
15-
16-
/// <summary>
17-
/// Gets or sets the depth of the nested cache folders structure to store the images. Defaults to 8.
18-
/// </summary>
19-
public uint CacheFolderDepth { get; set; } = 8;
20-
2111
/// <summary>
2212
/// Gets or sets the optional cache root folder path.
2313
/// <para>
@@ -31,5 +21,15 @@ public class PhysicalFileSystemCacheOptions
3121
/// </para>
3222
/// </summary>
3323
public string CacheRootPath { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the cache folder name.
27+
/// </summary>
28+
public string CacheFolder { get; set; } = "is-cache";
29+
30+
/// <summary>
31+
/// Gets or sets the depth of the nested cache folders structure to store the images. Defaults to 8.
32+
/// </summary>
33+
public uint CacheFolderDepth { get; set; } = 8;
3434
}
3535
}

0 commit comments

Comments
 (0)