I want to clear custom cache when items at specific path are published. Here is what I tried so far.
Solution 1:
I created a custom event handler for publish:itemProcessed
and publish:itemProcessed:remote
which works fine for added and updated item but not deleted items. Before clearing cache I want to make sure item that is deleted is from specific path but Factory.GetDatabase(WebDatabaseName).GetItem(itemID)
would give me null, think because it is already processed.
Solution 2:
I created custom processor CustomPublishProcessor
and patched it in publish
pipeline after "*[@type='Sitecore.Publishing.Pipelines.Publish.ProcessQueue, Sitecore.Kernel']"
Here I am able to get ProcessedPublishingCandidates
but clearing cache here won't be a good decision since it won't clear cache on remote CD servers.
So I created one event handler on publish:end
and publish:end:remote
so that cache on all servers are cleared.
I decided to pass some information to publish end event so that cache is getting cleared for perticular so I tried to set a cookie in CustomPublishProcessor
and read it from handler.
Here is the code to set cookie
HttpCookie clearSolutionCacheCookie = new HttpCookie(ClearSolutionCookieKey);
clearSolutionCacheCookie.Value = "true";
HttpContext.Current.Response.Cookies.Add(clearSolutionCacheCookie);
it gives me HttpContext.Current
as null.
I think I need to raise a custom event from CustomPublishProcessor
to clear those cookie but I am not sure how to start.
I want experts' opinions here if I am over-doing customization? Am I missing something out of the box feature that does it. Can I achieve it by tweaking either of my solutions or I am completely on a wrong track.