-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
  • Which Sitecore version?
    – Marek Musielak
    Commented Dec 9, 2020 at 11:23
  • it's sitecore 9.3
    – S. Ray
    Commented Dec 9, 2020 at 12:20
  • Maybe try this then? medium.com/@markgibbons25/…
    – Marek Musielak
    Commented Dec 9, 2020 at 13:11
  • htmlCache.RemoveKeysContaining(item.Paths.FullPath); is not working
    – S. Ray
    Commented Dec 10, 2020 at 4:45
  • You're using Sitecore.Publishing.SmartHtmlCacheClearer?
    – Marek Musielak
    Commented Dec 10, 2020 at 7:08

1 Answer 1

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
    Commented Dec 10, 2020 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
    Commented Dec 10, 2020 at 16:56

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