Sitecore Smart HTML Cache Clearance

Hello
Folks, I hope you are all doing well.

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

In
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.

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

https://markstiles.net/Blog/2011/05/26/partial-html-cache-clearing.aspx

), 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.

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

Happy
Sitecoring.! 
J

Share

Read More