This isn't a question I've seen around, usually it's 'EPiServer isn't clearing the output cache'. I'm trying to achieve the opposite. Each time a page is published the entire cache is dropped and as the client publishes several times a day, this is frustrating.
I'm using the [ContentOutputCache]
attribute and tried to implement a httpCacheVaryByCustom
rule with an accompanying scheduled task in EPiServer to invalidate the cache when we decide to i.e. bundle updates together and invalidate at a predetermined time.
I've tested this rule and it works using:
public override string GetVaryByCustomString(HttpContext context, string custom)
I was under the impression that by using this type of caching rule it would stop EPiServer dumping my cache whenever something is published / media uploaded.
It doesn't though is there a way to stop this from happening?
I've had success by using the standard [OutputCache] with the same custom string rule the only problem with this is that editors will always see a cached version of the page they are editing.
The application settings I have in my web.config for EPiServer are:
<applicationSettings globalErrorHandling="Off" operationCompatibility="DynamicProperties" uiSafeHtmlTags="b,i,u,br,em,strong,p,a,img,ol,ul,li" disableVersionDeletion="false"
httpCacheability="Public" uiEditorCssPaths="~/assets/css/styles.css, ~/assets/css/editor.css" urlRebaseKind="ToRootRelative"
pageUseBrowserLanguagePreferences="false" uiShowGlobalizationUserInterface="false" subscriptionHandler="EPiServer.Personalization.SubscriptionMail,EPiServer"
uiMaxVersions="20" pageValidateTemplate="false" utilUrl="~/util/"
uiUrl="~/EPiServer/CMS/" httpCacheExpiration="01:00:00" httpCacheVaryByCustom="invalidateSiteCache" />
A custom
GetVaryByCustomString
function will determine when the cache is invalidated, but any request for content that is using theContentOutputCache
is checked against a master cache keyEpiserver.DataFactoryCache.Version
. This version number is incremented any time content is published, updated etc, and the cache is invalidated if the version number is changed.To understand what you need to do, I recommend using a decompiler (e.g. DotPeek) and looking at the
ContentOutputCacheAttribute
andOutputCacheHandler
classes in the Episerver dll.You will need to:
EPiServer.Web.OutputCacheHandler
ValidateOutputCache(...)
that still callsOutputCacheHandler.UseOutputCache(...)
but ignores the cache version numberContentOutputCacheAttribute
OnResultExecuting(ResultExecutingContext filterContext)
using the same logic as the current method (this is where a decompiler is useful), but that adds a callback to your new validate method instead of the current one. Unfortunately we can't inject the new handler because the validate method is passed statically.e.g.
[ContentOutputCache]