Customsing the Sitecore HTML cache clearer

Saturday, May 28, 2016

The default Sitecore CacheClearer can be a bit heavy handed, dumping all of the HTML cache for a site every time an item is published. This isn't always what is required, sometimes there are certain areas of the content tree that you're confident don't get cached, and as such you don't want a publish of these items to cause the cache clear to take place.

I worked with a customer recently who required just that functionality. It turns out it was rather easy to implement by overriding the default HtmlCacheClearer with a custom version. This would check a series of content paths stored in an app setting and if the published item was located under one then the publish would be ignored and the caches remain populated.

My first attempt at this used a list of ID's instead of a list of paths, however as we wanted ignore an item and all of its children this required a look of the item from ID and then an Axes comparison, which was a lot slower than the string comparison on the path being used now.

To patch it in instead of the default HTMLCacheClearer, it is a simple case of replacing the existing instance with the new one and adding the new app setting

If you want to include this functionality in your project then you can download it from GitHub

comments powered by Disqus