Clearing a custom delivery server cache on publish

We have a non-Sitecore custom cache (which follows identical rules on both delivery servers and the authoring server) responsible for building up a hierarchy that is derived from a combination of Sitecore items and data in a custom database. The only trigger that can invalidate this cache is if the Sitecore items are modified and republished. So how do we pick up when this happens?

Our previous implementation hooked in to the Publish pipeline, and was basically a PublishProcessor that used a little bit of logic to determine if the item being published should trigger clearing the internal cache. The method itself looked something like this:

namespace Project.Pipelines.Publish  
{
    public class ClearListCache : PublishProcessor
    {
        public override void Process(PublishContext context)
        {
            // Clear our cache
        }
    }
}

This was then hooked up to the publish pipeline in Sitecore.config.

Our new implementation is an event handler that listens for the publish:end:remote (on delivery servers) or publish:end event (on the authoring server):

namespace Project.Pipelines.Publish  
{
    public class PublishEndClearCacheHandler
    {
        public void ClearCache(object sender, EventArgs args)
        {
            // Clear our cache
        }
    }
}

With the following in Sitecore.config (on the delivery server):

<event name="publish:end:remote">  
    <handler
        type="Project.Pipelines.Publish.PublishEndClearCacheHandler, Project"
        method="ClearCache" />
</event>  

The handler type is a string containing the assembly-qualified name of the event handler class - that is, the type name including the namespace, followed by a comma, followed by the assembly display name. The method string contains the name of the method on that type to invoke.

The handler for this particular event can also accept a PublishEndRemoteEventArgs instead of an EventArgs argument - however we didn't need it in this case.