Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to turn off render caching #294

Merged
merged 1 commit into from
Oct 31, 2024
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
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