This blog post provides a prototype solution that clears the output caches for all of the sites managed by an instance of the Sitecore ASP.NET web Content Management System without the need to specify those sites individually.
Update 13.December.2012: For updates to the code provided in this blog post, see the last two blog posts linked at the end of this page.
The default implementation of the event handler (the Sitecore.Publishing.HtmlCache class) for the publish:end and publish:end:remote clears the output caches for the sites specified for the event handler. For example, with the default configuration:
After publication, these event handlers clear the output cache for the managed site named website. If you add and rename sites, you need to remember to update these configurations. This could be frustrating and even error-prone if you have a number of Sitecore instances and add, delete, or rename managed sites frequently.
Instead, you might want to simply clear the output caches for all managed sites whenever you publish. You can achieve this objective with an override of this event handlers based on the following prototype:
SC = Sitecore;
HtmlCacheClearer : SC.Publishing.HtmlCacheClearer
sender, EventArgs args)
.Sites.Count > 0)
siteNames = (
siteNames = SC.Configuration.Factory.GetSiteNames();
" clearing HTML caches; "
+ siteNames.Length +
" possible sites."
SC.Sites.SiteContext site = SC.Configuration.Factory.GetSite(siteName);
SC.Caching.HtmlCache htmlCache = SC.Caching.CacheManager.GetHtmlCache(
"htmlCache for "
(htmlCache.InnerCache.Count < 1)
" no entries in output cache for "
" clearing output cache for "
If you use the <sites> element within the <handler> element to specify sites, the ClearCaches() method clears the output caches for those sites. Otherwise, it clears the output caches for all sites that cache output and have entries in those caches. Note that the default implementation uses the method name ClearCache() and I named the method ClearCaches(). Therefore you can also use the ClearCache() method to get the default functionality.
You can use a Web.config include file (/App_Config/Include/Sitecore.Sharedsource.HtmlCacheClearer.config in my case) such as the following to enable this event handler for these events:
This overrides the default handlers for these events (it could instead delete the defaults handlers and add new ones), updates the method attribute of the <handler> element from ClearCache to ClearCaches, and removes the <sites> elements from within those <handler> elements.
Why is this not the standard behaviour? I didn't find any clues in the caching documentation pointing to this, which lead to avoidable error and error-diagnosis. I've implemented something like www.matthewkenny.com/.../ as I found it easier to change Sitecore behaviour than to update the documentation for creating a site to include the extra unexpected steps.
@Jan: I agree that requiring this configuration seems silly and should be optional at best. Unfortunately, "why" questions have to go through product management, and feature requests have to go through the support portal.
I strongly guess that was no management decision but most likely that part was developed by a new developer and never touched again. I've filed a support issue, I hope it will help.
Wouldn't it make more sense if the cache clearing would be only on Sitecore.Context.Site.Name or Full Publish or... something like that? By to way is this still case on version 8?