Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/Umbraco.Web.Common/RuntimeMinification/SmidgeOptionsSetup.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,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> _runtimeMinificatinoSettings;
private readonly IOptions<RuntimeMinificationSettings> _runtimeMinificationSettings;

public SmidgeOptionsSetup(IOptions<RuntimeMinificationSettings> runtimeMinificatinoSettings)
=> _runtimeMinificatinoSettings = runtimeMinificatinoSettings;
=> _runtimeMinificationSettings = 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.
/// Also sets the cache buster type such that public facing bundles will use the configured method.
/// </summary>
/// <param name="options"></param>
/// <param name="options">Instance of <see cref="SmidgeOptions"></see> to configure.</param>
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 = _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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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", $"{runtimeMinificationSettings.Value.CacheBuster} is not a valid value for RuntimeMinificationCacheBuster."),
};

_cacheBusterType = cacheBusterType;
Expand Down