diff --git a/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerAppSettingsModel.cs b/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerAppSettingsModel.cs index 375072ff..5d27cffd 100644 --- a/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerAppSettingsModel.cs +++ b/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerAppSettingsModel.cs @@ -9,5 +9,6 @@ public class ScriptManagerAppSettingsModel = new Dictionary(); public string[] DisabledModules { get; set; } = Array.Empty(); + public bool DisableRenderCaching { get; set; } = false; } } diff --git a/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerConfigModel.cs b/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerConfigModel.cs index f33978c0..ae96695d 100644 --- a/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerConfigModel.cs +++ b/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/Models/ScriptManagerConfigModel.cs @@ -8,5 +8,6 @@ public class ScriptManagerConfigModel Array.Empty(); public string[] DisabledModules { get; set; } = Array.Empty(); + public bool DisableRenderCaching { get; set; } = false; } } diff --git a/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/ScriptManagerConfigurationService.cs b/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/ScriptManagerConfigurationService.cs index b9c5d5e2..9fd18ecf 100644 --- a/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/ScriptManagerConfigurationService.cs +++ b/src/SeoToolkit.Umbraco.ScriptManager.Core/Config/ScriptManagerConfigurationService.cs @@ -24,7 +24,8 @@ public override ScriptManagerConfigModel GetSettings() Alias = it.Key, Enabled = it.Value.Enabled }).ToArray(), - DisabledModules = settings.DisabledModules + DisabledModules = settings.DisabledModules, + DisableRenderCaching = settings.DisableRenderCaching }; } } diff --git a/src/SeoToolkit.Umbraco.ScriptManager.Core/Services/ScriptManagerService.cs b/src/SeoToolkit.Umbraco.ScriptManager.Core/Services/ScriptManagerService.cs index da8da355..b8404b30 100644 --- a/src/SeoToolkit.Umbraco.ScriptManager.Core/Services/ScriptManagerService.cs +++ b/src/SeoToolkit.Umbraco.ScriptManager.Core/Services/ScriptManagerService.cs @@ -7,6 +7,8 @@ using SeoToolkit.Umbraco.ScriptManager.Core.Models.Business; using SeoToolkit.Umbraco.ScriptManager.Core.Caching; using SeoToolkit.Umbraco.ScriptManager.Core.Constants; +using SeoToolkit.Umbraco.Common.Core.Services.SettingsService; +using SeoToolkit.Umbraco.ScriptManager.Core.Config.Models; namespace SeoToolkit.Umbraco.ScriptManager.Core.Services { @@ -14,12 +16,17 @@ public class ScriptManagerService : IScriptManagerService { private readonly IScriptRepository _scriptRepository; private readonly DistributedCache _distributedCache; + private readonly ISettingsService _settings; private readonly IAppPolicyCache _cache; - public ScriptManagerService(IScriptRepository scriptRepository, AppCaches appCaches, DistributedCache distributedCache) + public ScriptManagerService(IScriptRepository scriptRepository, + AppCaches appCaches, + DistributedCache distributedCache, + ISettingsService settings) { _scriptRepository = scriptRepository; _distributedCache = distributedCache; + _settings = settings; _cache = appCaches.RuntimeCache; } @@ -66,16 +73,21 @@ public Script Get(int id) public ScriptRenderModel GetRender() { - return _cache.GetCacheItem($"{CacheConstants.ScriptManager}GetRender", () => + if (_settings.GetSettings().DisableRenderCaching) + return DoGetRender(); + + return _cache.GetCacheItem($"{CacheConstants.ScriptManager}GetRender", DoGetRender); + } + + private ScriptRenderModel DoGetRender() + { + var renderModel = new ScriptRenderModel(); + foreach (var script in GetAll()) { - var renderModel = new ScriptRenderModel(); - foreach (var script in GetAll()) - { - script.Definition.Render(renderModel, script.Config); - } + script.Definition.Render(renderModel, script.Config); + } - return renderModel; - }); + return renderModel; } private void ClearCache()