Sitecore Smart HTML Cache Clearance

Folks, I hope you are all doing well.

HTML Cache clearance – As the name suggest it clears HTML Cache for a site in a
smarter way.

Sitecore Content tree if you are building a site for two or more different
countries/regions and as you publish any content in any of the site than you can observe via Cache.aspx that HTML
Cache for each site gets cleared. Which should not happen.

So in
order to achieve this goal, I did analysis and found that we have to override
the default implementation of cache clearance when we publish any item in
content tree. But what if we publish any template or media item or anything
other than content, than at that time whole html cache should get clear. Also
when we publish the whole site at that time html cache for all the sites should
get clear. Smart HTML Cache Clearance will handle all the scenarios efficiently
and accurately when you publish any item on local or on remote site. Also when
it needs to clear the entire HTML Cache for all the sites than the default
implementation as written by Sitecore will handle our job.

whenever we face such challenges we google it, so similarly I did and found
blog of Mark Stiles(

), which helped me to achieve
objective but that was for remote publish, what if Sitecore is enabled on
production server? Or what if we want to test it in local? So for that I tried
to modify the code and got the solution.

Step 1: Create a class called SmartHtmlCacheClearer in your library.

Step 2: Replace publish:end and publish:end:remote handler to refer the SmartHtmlCacheClearer class in web.config

Now we have
to add the reference of this class to the events section in web.config file and
allow Sitecore to execute this code instead of Sitecore default code.

We just have
to modify the handler for publish:end and publish:end:remote.

That’s it.

Please specify the exact method name in handler which should be executed.



Read More