-2

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.

Clear individual Rendering/Component Html cache

8
0

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>
2
  • 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. Ray Dec 10 '20 at 12:46
  • 2
    Note 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 on publish:end:remote event – Jeroen Dec 10 '20 at 16:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.