This is either one of those things you may never have to use, or you come across a requirement and realize this is exactly what you need and just didn’t know what it was called. I fell into the latter category when I needed to programmatically refresh images in my media library that were cached in my company’s content delivery syndicator – Akamai. Thankfully, @AlexShyba pointed me in the right direction.
Clear external image/CDN cache when a media item gets published.
The PublishProcessor object is located in the Sitecore.Publishing.Pipelines.Publish namespace. We will need to inherit from this object to your own class and override the Process(PublishContext) method with our own custom functionality.
The PublishContext that’s passed in by Sitecore’s publishing processor has a list of items being published. All we have to do is iterate through the list and use the Sitecore Item’s Path.IsMediaItem property to determine if it’s a media library item or not. If it is, we just pass it or its full path to a custom method and use whatever API is provided by your CDN of choice to force refresh on it.