This entry about the TrackPublishing processor in the publishItem pipeline used to track information about publishing operations is part of a series of blog posts about a custom approach to clearing output caches for managed sites with the Sitecore ASP.NET web Content Management System (CMS) and Experience Platform (XP). For more information, see the Resources section at the end of this blog post.
The TrackPublishing processor in the publishItem pipeline does nothing (exits without aborting the pipeline) if the publishing operation did not affect the item passed through the publishItem pipeline, such as in some publishing scenarios when the publishing target database already contains that revision of the item. For efficiency, the processor also terminates if conditions indicate to clear caches completely, as all subsequent logic in this processor is redundant or irrelevant in that case.
If the published item does not exist in the source database, then its deletion must have been published. In this case it is not possible to determine the managed sites affected by a publishing operation, and the TrackPublishing processor indicates that solutions should clear all output caches, and then exits.
Otherwise, the TrackPublishing processor attempts to determine the managed sites for which the solution should clear output caches after publishing the item. To determine those sites, it checks the Sites field in the published item and each of its ancestors. It adds any such values (which can be pipe-separated lists) to the list of sites for which to clear output caches. To that list it adds any managed site definitions for which the start item is the published item or one of its ancestors.
If the TrackPublishing processor cannot determine which the managed sites for which the solution should clear output caches after publishing the item, it indicates that solutions should clear all output caches, and then exits.
The TrackPublishing processor in the publishItem pipeline updates information about publishing in object exposed by the OutputCacheClearingOptions property of that type in the Sitecore.Sharedsource.Publishing.ClearSiteOutputCaches static class. While this may seem suboptimal, it appears to work, when intercepting publishing in other locations could present additional challenges.
The Sitecore.Sharedsource.Publishing.ClearSiteOutputCaches class exposes a Reset() method to clear that OutputCacheClearingOptions property. An event handler for the publish:end event that I hope to describe elsewhere calls the Reset method(). Because the OutputCacheClearingOptions property is for use only by the Sitecore.Sharedsource.Publishing.ClearSiteOutputCaches pipeline, it builds up information during one publishing process, after which the publish:end event handler resets that information (assuming synchronous event handling…).