Skip to content

Commit

Permalink
Set Smidge cachebuster type
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Hartfield committed Feb 2, 2025
1 parent 7dc6e3e commit 5ae690b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using Smidge.Cache;
using Smidge.Options;
using Umbraco.Cms.Core.Configuration.Models;

Expand All @@ -12,11 +13,25 @@ public SmidgeOptionsSetup(IOptions<RuntimeMinificationSettings> runtimeMinificat
=> _runtimeMinificatinoSettings = runtimeMinificatinoSettings;

/// <summary>
/// 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.
/// </summary>
/// <param name="options"></param>
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);
}
}

0 comments on commit 5ae690b

Please sign in to comment.