Skip to content

Commit

Permalink
Add option to turn off render caching (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdemooij9 authored Oct 31, 2024
1 parent 710fc85 commit 8c48a65
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class ScriptManagerAppSettingsModel
= new Dictionary<string, ScriptManagerDefinitionAppSettingsModel>();

public string[] DisabledModules { get; set; } = Array.Empty<string>();
public bool DisableRenderCaching { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public class ScriptManagerConfigModel
Array.Empty<ScriptManagerDefinitionConfigModel>();

public string[] DisabledModules { get; set; } = Array.Empty<string>();
public bool DisableRenderCaching { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@
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
{
public class ScriptManagerService : IScriptManagerService
{
private readonly IScriptRepository _scriptRepository;
private readonly DistributedCache _distributedCache;
private readonly ISettingsService<ScriptManagerConfigModel> _settings;
private readonly IAppPolicyCache _cache;

public ScriptManagerService(IScriptRepository scriptRepository, AppCaches appCaches, DistributedCache distributedCache)
public ScriptManagerService(IScriptRepository scriptRepository,
AppCaches appCaches,
DistributedCache distributedCache,
ISettingsService<ScriptManagerConfigModel> settings)
{
_scriptRepository = scriptRepository;
_distributedCache = distributedCache;
_settings = settings;
_cache = appCaches.RuntimeCache;
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8c48a65

Please sign in to comment.