From 5ae690b30e3be014fa8125004c7b2418a83a438b Mon Sep 17 00:00:00 2001 From: Simon Hartfield Date: Sun, 2 Feb 2025 12:25:27 +0000 Subject: [PATCH 1/3] Set Smidge cachebuster type --- .../RuntimeMinification/SmidgeOptionsSetup.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs index 37701928c61f..6d4d40f91ca8 100644 --- a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs +++ b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Options; +using Smidge.Cache; using Smidge.Options; using Umbraco.Cms.Core.Configuration.Models; @@ -12,11 +13,25 @@ public SmidgeOptionsSetup(IOptions runtimeMinificat => _runtimeMinificatinoSettings = runtimeMinificatinoSettings; /// - /// Configures Smidge to use in-memory caching if configured that way or if certain cache busters are used + /// Configures Smidge to use in-memory caching if configured that way or if certain cache busters are used. As well as the cache buster type. /// /// public void Configure(SmidgeOptions options) - => options.CacheOptions.UseInMemoryCache = _runtimeMinificatinoSettings.Value.UseInMemoryCache || + { + options.CacheOptions.UseInMemoryCache = _runtimeMinificatinoSettings.Value.UseInMemoryCache || _runtimeMinificatinoSettings.Value.CacheBuster == RuntimeMinificationCacheBuster.Timestamp; + + + Type cacheBusterType = _runtimeMinificatinoSettings.Value.CacheBuster switch + { + RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster), + RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster), + RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster), + _ => throw new NotImplementedException(), + }; + + options.DefaultBundleOptions.DebugOptions.SetCacheBusterType(cacheBusterType); + options.DefaultBundleOptions.ProductionOptions.SetCacheBusterType(cacheBusterType); + } } From 7c1fc1db75ab639c2a184a472db409c35f017f33 Mon Sep 17 00:00:00 2001 From: Simon Hartfield Date: Mon, 3 Feb 2025 17:27:52 +0000 Subject: [PATCH 2/3] Amend exception and fix typo --- .../RuntimeMinification/SmidgeOptionsSetup.cs | 13 ++++++------- .../RuntimeMinification/SmidgeRuntimeMinifier.cs | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs index 6d4d40f91ca8..d08556aff30a 100644 --- a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs +++ b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs @@ -7,10 +7,10 @@ namespace Umbraco.Cms.Web.Common.RuntimeMinification; public class SmidgeOptionsSetup : IConfigureOptions { - private readonly IOptions _runtimeMinificatinoSettings; + private readonly IOptions _runtimeMinificationSettings; public SmidgeOptionsSetup(IOptions runtimeMinificatinoSettings) - => _runtimeMinificatinoSettings = runtimeMinificatinoSettings; + => _runtimeMinificationSettings = runtimeMinificatinoSettings; /// /// Configures Smidge to use in-memory caching if configured that way or if certain cache busters are used. As well as the cache buster type. @@ -18,17 +18,16 @@ public SmidgeOptionsSetup(IOptions runtimeMinificat /// public void Configure(SmidgeOptions options) { - options.CacheOptions.UseInMemoryCache = _runtimeMinificatinoSettings.Value.UseInMemoryCache || - _runtimeMinificatinoSettings.Value.CacheBuster == + options.CacheOptions.UseInMemoryCache = _runtimeMinificationSettings.Value.UseInMemoryCache || + _runtimeMinificationSettings.Value.CacheBuster == RuntimeMinificationCacheBuster.Timestamp; - - Type cacheBusterType = _runtimeMinificatinoSettings.Value.CacheBuster switch + Type cacheBusterType = _runtimeMinificationSettings.Value.CacheBuster switch { RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster), RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster), RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster), - _ => throw new NotImplementedException(), + _ => throw new ArgumentOutOfRangeException("CacheBuster", "RuntimeMinification.CacheBuster is not a valid value") }; options.DefaultBundleOptions.DebugOptions.SetCacheBusterType(cacheBusterType); diff --git a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs index b06f8d06880a..73451960b469 100644 --- a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs +++ b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs @@ -79,7 +79,7 @@ public SmidgeRuntimeMinifier( RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster), RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster), RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster), - _ => throw new NotImplementedException(), + _ => throw new ArgumentOutOfRangeException("CacheBuster", "RuntimeMinification.CacheBuster is not a valid value") }; _cacheBusterType = cacheBusterType; From 1b93822e45600683d360d2e97eee8a3f6c0de981 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 4 Feb 2025 07:18:59 +0100 Subject: [PATCH 3/3] Minor tweak to comment and exception message. --- .../RuntimeMinification/SmidgeOptionsSetup.cs | 7 ++++--- .../RuntimeMinification/SmidgeRuntimeMinifier.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs index d08556aff30a..2452e30f661f 100644 --- a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs +++ b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs @@ -13,9 +13,10 @@ public SmidgeOptionsSetup(IOptions runtimeMinificat => _runtimeMinificationSettings = runtimeMinificatinoSettings; /// - /// Configures Smidge to use in-memory caching if configured that way or if certain cache busters are used. As well as the cache buster type. + /// 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. /// - /// + /// Instance of to configure. public void Configure(SmidgeOptions options) { options.CacheOptions.UseInMemoryCache = _runtimeMinificationSettings.Value.UseInMemoryCache || @@ -27,7 +28,7 @@ public void Configure(SmidgeOptions options) RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster), RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster), RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster), - _ => throw new ArgumentOutOfRangeException("CacheBuster", "RuntimeMinification.CacheBuster is not a valid value") + _ => throw new ArgumentOutOfRangeException("CacheBuster", $"{_runtimeMinificationSettings.Value.CacheBuster} is not a valid value for RuntimeMinificationCacheBuster."), }; options.DefaultBundleOptions.DebugOptions.SetCacheBusterType(cacheBusterType); diff --git a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs index 73451960b469..cd0b80d1dd14 100644 --- a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs +++ b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs @@ -79,7 +79,7 @@ public SmidgeRuntimeMinifier( RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster), RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster), RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster), - _ => throw new ArgumentOutOfRangeException("CacheBuster", "RuntimeMinification.CacheBuster is not a valid value") + _ => throw new ArgumentOutOfRangeException("CacheBuster", $"{runtimeMinificationSettings.Value.CacheBuster} is not a valid value for RuntimeMinificationCacheBuster."), }; _cacheBusterType = cacheBusterType;