Since Sitecore 8 version has been released I have been experiencing issues with caching. First is that one I described earlier, then I figured out that one of my renderings is being placed inside of another and it applies caching from the parent rendering and that was wrong apparently 🙂

In result I came up with idea that I need to see what cache keys are being generated for each of my renderings on the page.

Just wrapped that into a nuget package to share with you guys! So that is just another Helpfulcore module for your Sitecore solution.
If you go to your nuget Package Manager Console and install this to your website project

Install-Package Helpfulcore.CacheKeyProfiling

You will be able to see something like this at your page source html:

<!-- Site name: website -->
<!-- Database: web -->
<!-- Language: da -->
<!-- Cache Key list: -->
<!-- controller::Seo#Metadata_#lang:DA_#area:Seo_#data:/sitecore/content/sites/website/Home_#parm:_#qs: -->
<!-- view::/Views/Layouts/_Partials/Stylesheets.cshtml_#lang:DA -->
<!-- view::/Views/Layouts/_Partials/Icons.cshtml_#lang:DA -->
<!-- view::/Views/Layouts/_Partials/Fonts.cshtml_#lang:DA -->
<!-- view::/Views/Layouts/_Partials/HeadExtras.cshtml_#lang:DA -->
<!-- view::/Views/Layouts/_Partials/BrowserUpgrade.cshtml_#lang:DA -->
<!-- view::/Views/Layouts/_Partials/GlobalCookieMessage.cshtml_#lang:DA -->
<!-- view::/Views/Layouts/_Partials/SiteLogos.cshtml_#lang:DA -->
<!-- controller::Navigation#MainNavigation_#lang:DA_#area:Navigation_#data:/sitecore/content/sites/website/Home_#login:True_#parm:_#qs: -->
<!-- controller::Navigation#MainSideNavigation_#lang:DA_#area:Navigation_#data:/sitecore/content/sites/website/Home_#login:True_#parm:_#qs: -->
<!-- view::/Views/SimpleContent/Hero.cshtml_#lang:DA_#data:/sitecore/content/sites/website/website-content/heros/hero-test_#parm:_#qs: -->
<!-- view::/Views/LiveFeeds/JackpotsNow.cshtml_#lang:DA_#data:/sitecore/content/sites/website/website-content/sidebar/website-jackpot-boxes/jackpotter-nu_#parm:_#qs: -->
<!-- view::/Views/LiveFeeds/NewWinners.cshtml_#lang:DA_#data:/sitecore/content/sites/website/website-content/sidebar/website-winner-boxes/nye-vindere_#parm:_#qs: -->
<!-- view::/Views/SimpleContent/BoxLink.cshtml_#lang:DA_#data:/sitecore/content/sites/website/website-content/sidebar/website-link-boxes/box-link-test_#parm:_#qs: -->
<!-- controller::Games#GameList_#lang:DA_#area:Games_#data:/sitecore/content/sites/website/Home_#dev:Default#isMobile:False_#login:True_#parm:Hide Title=1&amp;Associated Tags={EA74A9BD-38C4-4012-80AE-95D443479470}|{2CCE6B9C-398A-457A-B86E-8F7D1B57B369}&amp;Page Size=17&amp;Hide Pagination=1&amp;Autocomplete Page Size=50_#qs: -->
<!-- view::/Views/SimpleContent/BoxImage.cshtml_#lang:DA_#data:/sitecore/content/sites/website/website-content/sidebar/website-image-boxes/box-image-test-motiejus_#parm:_#qs: -->
<!-- view::/Views/SimpleContent/BoxText.cshtml_#lang:DA_#data:/sitecore/content/sites/website/website-content/sidebar/website-text-boxes/box_#parm:_#qs: -->
<!-- controller::Footer#Footer_#lang:DA_#area:Footer_#data:/sitecore/content/sites/website/Home_#parm:_#qs: -->
<!-- view::/Views/Layouts/_Partials/BottomScripts.cshtml_#lang:DA -->

This way you can see what cache keys are being generated during the pipeline for each of rendering on your page.
Personally for me that helped a lot to resolve my rendering caching issues on the website.
Will describe the module a bit:

Package contents:

– /bin/Helpfulcore.CacheKeyProfiling.dll
– /App_Config/Include/Helpfulcore/Helpfulcore.CacheKeyProfiling.config
– /Views/Shared/CacheKeyProfiling/CacheKeys.cshtml

Pipeline injection

In the include config file Helpfulcore.CacheKeyProfiling.config I am injecting into pipeline and saving generated cache keys into current request.

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <mvc.renderRendering>
        <processor type="Helpfulcore.CacheKeyProfiling.Pipelines.RenderRendering.GatherCacheKeys, Helpfulcore.CacheKeyProfiling" patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.RenderRendering.RenderFromCache, Sitecore.Mvc']" />
      </mvc.renderRendering>
    </pipelines>
  </sitecore>
</configuration>

Usage

And then I have a view /Views/Shared/CacheKeyProfiling/CacheKeys.cshtml which reads previously saved collection and outputs it as HTML comments.
In order to render it you will need to write one extra line of code on your layout file. Render it at the bottom of the page for convenience.

	@Html.RenderCacheKeys()

And that’s it folks!
The source code for the package is at GitHub here

Share article
See also

MVC renderings with xWrap framework – Sitecore Experience Wrapper

Read more Volodymyr Hil 10.12.2018

Introducing xWrap framework – Sitecore Experience Wrapper

Read more Volodymyr Hil 09.12.2018

A recap from Sitecore Symposium 2018 and MVP summit

Read more Volodymyr Hil 25.10.2018

Using the service bus to transfer messages between instance roles

Read more Volodymyr Hil 10.06.2018

Using Swagger in Sitecore solution as a helix feature

Read more Volodymyr Hil 19.02.2018