How can I clear an individual rendering cache from my site on publishing
Sitecore item
programmatically. I followed below article which did not work for me.
1 Answer
I recommend after publish to clear caches from the whole site to make sure there are no caches left. This also clears component level caches. Here is an example code how to achieve this:
var context = SiteContext.GetSite(site.Name);
if (context != null && context.CacheHtml)
{
context.Caches?.HtmlCache?.Clear();
}
You can hook to publishEnd like this:
<event name="publish:end">
<handler type="namespace.HtmlCacheClearer, DLLFileName" method="ClearCache" />
</event>
-
Thanks so much for your response. It's not working for us. could you please suggest any other idea. Also we do not want to delete site cache in every publish.– S. RayCommented Dec 10, 2020 at 12:46
-
2Note that this happens automatically in Sitecore 9.3 unless you set
preventHtmlCacheClear
to false on site definition. Unless your CD is on the same box as CA something like this also needs to run onpublish:end:remote
event– JeroenCommented Dec 10, 2020 at 16:56
Sitecore.Publishing.SmartHtmlCacheClearer
?