I am working on Sitecore SXA
and we are planning to implement cache
. I have enabled it on Site level
and added cache on rendering level
for all the sites inside tenant. Now my question is how can we check cache is enabled at browser level or check cache key
somewhere in Sitecore (log file). How can we check its key (cache key)? Just want to check cache is working fine at our site?
-
Did you check this: sitecore.stackexchange.com/questions/31945/…?– Sumit UpadhyayCommented Jun 7, 2022 at 11:17
-
This link is not related to the cache key.– NishaCommented Jun 7, 2022 at 11:35
-
3@Nisha alan-null.github.io/2019/02/cache-viewer– Alan PłócieniakCommented Jun 7, 2022 at 12:02
-
@AlanPłócieniak thank you for your comment.– NishaCommented Jun 8, 2022 at 15:18
2 Answers
There is no built in tool with Sitecore that allows you to easily inspect the cache keys that have been constructed in the HTML cache. To do this you need to write your own inspection page or tool. Alternatively you could install Sitecore Rocks
– the tool that integrates with Visual Studio which allows you to view the cache keys. To do this Manage your site from within the Visual Studio Sitecore Explorer
and select the caches tab. Scroll down to “yoursitename[html]
” and double click it. The Explore cache window should appear and you should then be able to see the cache keys currently in the cache e.g.:
You can also check cache details on the below paths :
https://hostname/sitecore/admin/stats.aspx
https://hostname/sitecore/admin/cache.aspx
The processor used by default on Sitecore does not log the cache key to the logs. The best you can do here is to patch the processor which generates the cache key with a custom processor. It would go something like below:
LogCacheKey.cs
using Sitecore.Mvc.Pipelines.Response.RenderRendering;
using Sitecore.Mvc.Presentation;
namespace HabitatHome.Foundation.Caching.Pipelines
{
public class LogCacheKey: GenerateCacheKey
{
public GenerateCustomCacheKey(RendererCache rendererCache) : base(rendererCache)
{
}
protected override string GenerateKey(Rendering rendering, RenderRenderingArgs args)
{
var cacheKey = base.GenerateKey(rendering, args);
// Add logging here
Sitecore.Diagnostics.Log.Info($"Cached the rendering {rendering.RenderingItem.Name} with cacheKey {cacheKey}");
return cacheKey;
}
}
}
HabitatHome.Foundation.Caching.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<mvc.renderRendering>
<processor patch:instead="processor[@type='Sitecore.Mvc.Pipelines.Response.RenderRendering.GenerateCacheKey, Sitecore.Mvc']"
type="HabitatHome.Foundation.Caching.Pipelines.LogCacheKey, HabitatHome.Foundation.Caching" resolve="true" />
</mvc.renderRendering>
</pipelines>
</sitecore>
</configuration>
This is only a rough idea, you can include more information as required in the logs.