Skip to content

Commit 2422a02

Browse files
SimonHartfieldSimon HartfieldAndyButland
authored
Set Smidge cachebuster type (#18198)
* Set Smidge cachebuster type * Amend exception and fix typo * Minor tweak to comment and exception message. --------- Co-authored-by: Simon Hartfield <[email protected]> Co-authored-by: Andy Butland <[email protected]>
1 parent 7dc6e3e commit 2422a02

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
using Microsoft.Extensions.Options;
2+
using Smidge.Cache;
23
using Smidge.Options;
34
using Umbraco.Cms.Core.Configuration.Models;
45

56
namespace Umbraco.Cms.Web.Common.RuntimeMinification;
67

78
public class SmidgeOptionsSetup : IConfigureOptions<SmidgeOptions>
89
{
9-
private readonly IOptions<RuntimeMinificationSettings> _runtimeMinificatinoSettings;
10+
private readonly IOptions<RuntimeMinificationSettings> _runtimeMinificationSettings;
1011

1112
public SmidgeOptionsSetup(IOptions<RuntimeMinificationSettings> runtimeMinificatinoSettings)
12-
=> _runtimeMinificatinoSettings = runtimeMinificatinoSettings;
13+
=> _runtimeMinificationSettings = runtimeMinificatinoSettings;
1314

1415
/// <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.
1618
/// </summary>
17-
/// <param name="options"></param>
19+
/// <param name="options">Instance of <see cref="SmidgeOptions"></see> to configure.</param>
1820
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 ==
2124
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+
}
2237
}

src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public SmidgeRuntimeMinifier(
7979
RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster),
8080
RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster),
8181
RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster),
82-
_ => throw new NotImplementedException(),
82+
_ => throw new ArgumentOutOfRangeException("CacheBuster", $"{runtimeMinificationSettings.Value.CacheBuster} is not a valid value for RuntimeMinificationCacheBuster."),
8383
};
8484

8585
_cacheBusterType = cacheBusterType;

0 commit comments

Comments
 (0)