What you can do is create an IInitializableModule
that attaches to the contentEvent PublishedContent
You can then check the type of the content expirying and then clear your cache
public class ClearCacheEvents : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>();
contentEvents.PublishedContent += ClearCache;
}
private void ClearCache(object sender, EPiServer.ContentEventArgs e)
{
if (e.Content is SomeContent)
{
//Logic to clear cache
}
}
}
I don't think there is a nice solution for that. What "content" are you caching? Is it possible to check for expired content when you get that cache?
You could check the StopPublish on the cached item. If the StopPublish date is changed, I believe your cache is invalidated.
Hi Andreas
A simple fix could be to just set the expiration date and time of your cached object, to the known StopPublish
property value (if it is not null).
As Tomas points out, if an editor changes the StopPublish
date to something earlier it would be removed from cache anyway. Then next time someone requests it, it is cached again with the new StopPublish
value.
This way you don't need to implement any custom content event handlers, at all.
I can use
IContentCacheKeyCreator
to create a cache key for some content, and then cache a item usingISynchronizedObjectInstanceCache
. If I would change that content via the admin interface, the cached item would be invalidated. However, if the same content would expire (StopPublish is passed) - the cached item is not invalidated. Does anyone know how to handle this?