forked from umbraco/Umbraco-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmidgeOptionsSetup.cs
More file actions
37 lines (31 loc) · 1.91 KB
/
Copy pathSmidgeOptionsSetup.cs
File metadata and controls
37 lines (31 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Microsoft.Extensions.Options;
using Smidge.Cache;
using Smidge.Options;
using Umbraco.Cms.Core.Configuration.Models;
namespace Umbraco.Cms.Web.Common.RuntimeMinification;
public class SmidgeOptionsSetup : IConfigureOptions<SmidgeOptions>
{
private readonly IOptions<RuntimeMinificationSettings> _runtimeMinificationSettings;
public SmidgeOptionsSetup(IOptions<RuntimeMinificationSettings> runtimeMinificatinoSettings)
=> _runtimeMinificationSettings = runtimeMinificatinoSettings;
/// <summary>
/// Configures Smidge to use in-memory caching if configured that way or if certain cache busters are used.
/// Also sets the cache buster type such that public facing bundles will use the configured method.
/// </summary>
/// <param name="options">Instance of <see cref="SmidgeOptions"></see> to configure.</param>
public void Configure(SmidgeOptions options)
{
options.CacheOptions.UseInMemoryCache = _runtimeMinificationSettings.Value.UseInMemoryCache ||
_runtimeMinificationSettings.Value.CacheBuster ==
RuntimeMinificationCacheBuster.Timestamp;
Type cacheBusterType = _runtimeMinificationSettings.Value.CacheBuster switch
{
RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster),
RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster),
RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster),
_ => throw new ArgumentOutOfRangeException("CacheBuster", $"{_runtimeMinificationSettings.Value.CacheBuster} is not a valid value for RuntimeMinificationCacheBuster."),
};
options.DefaultBundleOptions.DebugOptions.SetCacheBusterType(cacheBusterType);
options.DefaultBundleOptions.ProductionOptions.SetCacheBusterType(cacheBusterType);
}
}