The Power of Sitecore’s HTML Cache

Sitecore utilizes a number of layers of caching to help improve website performance. For the most part, these cache layers have been abstracted away from the developer. However, the most powerful caching layer is almost certainly the most underused layer. And arguably one of the most underused features in the entire platform.

Enter Sitecore’s HTML Cache

The HTML Cache is not a new feature to Sitecore. There are also a number of other very good blog posts covering the features. But from my experience, it is still often overlooked during the development process. My goal is to show you just how easy it is to make use of HTML caching and how powerful it can be.

What Can It Do For Me?

We all know caching is good but how good can HTML caching be? Just for example purposes, I ran a test on the homepage of a site I recently built. Once, with HTML caching enabled, and once without. I’ve gathered the statistics from Sitecore’s rendering statistics page (it can be found at /sitecore/admin/stats.aspx).

Homepage rendered 5 times without caching

no_caching

Homepage rendered 5 times with HTML caching enabled

with_caching

Since this was a simple site, the rendering times you see are quite low. Regardless, if we take the ContentPromo sublayout as an example, it’s average render time without caching was 5.9 ms. With caching, it’s average render time was a miniscule 1.2 ms, nearly a 5th of the time it took to render without caching. Take a look at the stats.aspx page on your site, I’ll bet you’ll see a number of components you’ll instantly want to cache.

How It Works

For the unfamiliar, for all cacheable sublayouts/renderings, Sitecore will cache the full HTML output of a rendering on initial load. On each subsequent load, the rendering’s output will be served from the HTML cache, rather than trying to dynamically render the control again.

To enable HTML caching, just navigate to your rendering in the Sitecore contenxt editor and find the ‘Caching’ section.

html_cache_content_editor

  • Cacheable: Select this checkbox to enable HTML caching. If your rendering has only one view, you’re done.
  • Clear on Index Update: Select if this component uses Sitecore’s ContentSearch API.
  • VaryByData: The cache will save a separate version of the HTML based on the datasource of the rendering (Sitecore will use the Context Item if no datasource is selected).
  • VaryByDevice: If you use this rendering on multiple devices, select this checkbox.
  • VaryByLogin: If the rendering is displayed differently for logged in users (but not different for each logged in user), select this checkbox.
  • VaryByParm: If you set custom parameters on the rendering/sublayout, select this checkbox.
  • VaryByQueryString: If querystring parameters affect the display of this rendering, select this checkbox.
  • VaryByUser: If this component displays user-specific information, select this checkbox.

If you have selected the correct checkboxes: Congratulations, you have just enabled Sitecore’s HTML Caching.

You can also configure the size of the HTML cache. By default each site is allocates 10MB toward the HTML cache. Since, by this point, I’m sure you’re contemplating enabling HTML caching on nearly every component, I recommend allocating as much memory as possible.

1
2
3
<sites>
    <site name="website" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />
</sites>

Hopefully, I’ve convinced you not only of the power of Sitecore’s HTML cache, but also how easy it is to use. Make sure it makes it onto your next project’s pre-launch checklist.

Leave a Reply