How to patch the Sitecore site list for cache clearing

I was struggling for a while with how to use Sitecore configuration patching in order to change this part:

<event name="publish:end">
      <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
        <sites hint="list">
          <site>website</site>
        </sites>
      </handler>
      <handler type="Sitecore.Publishing.RenderingParametersCacheClearer, Sitecore.Kernel" method="ClearCache" />
    </event>

I wanted to replace the default website with a list of sites. But when I tried to simply deploy a patch file with my own list of sites in it, only the last site element would be kept after the configuration processing.

To make a long story short, this is what worked:

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events timingLevel="custom">
      <event name="publish:end">
        <handler type="Sitecore.Publishing.HtmlCacheClearer,Sitecore.Kernel" method="ClearCache" patch:instead="*[@type='Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel']">
          <sites hint="list">
            <site>site1</site>
            <site>site2</site>
            <site>site3</site>
            <site>site4</site>
          </sites>
        </handler>
      </event>
    </events>
  </sitecore>
</configuration>

The ugly trick is to use patch:instead, but to be able to replace the handler element with your own element your type parameter must be different than the one you are replacing. So to accomplish this while still using the same type you can remove the space before the comma separating the class from the assembly. Sitecore will interpret this as different when the patch is processed and your list of sites will replace the original value in the rendered configuration.

 

2 thoughts on “How to patch the Sitecore site list for cache clearing”

  1. What would have worked is to add an extra attribute to the node, e.g.

    <events>
    <event name="publish:end">
    <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
    <sites hint="list">
    <site>
    <patch:delete />
    </site>
    <site hint="site1">site1</site>
    <site hint="site2">site2</site>
    </sites>
    </handler>
    </event>
    </events>

    And patch:delete the original website element if you needed to remove it.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s