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