停止EPiServer在发布时清除输出缓存 [英] Stop EPiServer clearing output cache on publish

查看:70
本文介绍了停止EPiServer在发布时清除输出缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是我遇到的问题,通常是"EPiServer没有清除输出缓存".我正在努力实现相反的目标.每次发布页面时,都会删除整个缓存,并且由于客户端每天要发布几次,所以这很令人沮丧.

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.

我正在使用 [ContentOutputCache] 属性,并尝试在EPiServer中实现带有随附计划任务的 httpCacheVaryByCustom 规则,以使我们决定绑定时使缓存无效一起更新并在预定时间失效.

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)

给我的印象是,通过使用这种缓存规则,无论何时发布/上传了媒体,EPiServer都将停止EPiServer转储我的缓存.

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?

通过将标准的[OutputCache]与相同的自定义字符串规则一起使用,我已经取得了成功,唯一的问题是编辑者将始终看到他们正在编辑的页面的缓存版本.

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.

我在web.config中为EPiServer设置的应用程序设置为:

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" />

推荐答案

自定义 GetVaryByCustomString 函数将确定何时使缓存无效,但将确定对使用 ContentOutputCache <根据主缓存键 Episerver.DataFactoryCache.Version 检查/code>.每当内容发布,更新等时,此版本号都会递增,并且如果更改版本号,则缓存将无效.

A custom GetVaryByCustomString function will determine when the cache is invalidated, but any request for content that is using the ContentOutputCache is checked against a master cache key Episerver.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.

要了解您需要做什么,我建议使用反编译器(例如 DotPeek )并查看在Episerver dll中的 ContentOutputCacheAttribute OutputCacheHandler 类中.

To understand what you need to do, I recommend using a decompiler (e.g. DotPeek) and looking at the ContentOutputCacheAttribute and OutputCacheHandler classes in the Episerver dll.

您将需要:

  1. EPiServer.Web.OutputCacheHandler
  2. 派生新的处理程序
  3. ValidateOutputCache(...)创建替代方法,该方法仍然调用 OutputCacheHandler.UseOutputCache(...),但忽略缓存版本号
  4. ContentOutputCacheAttribute
  5. 派生新属性
  6. 使用与当前方法相同的逻辑来覆盖方法 OnResultExecuting(ResultExecutingContext filterContext)(这是反编译器的作用),但是这会将回调添加到新的validate方法上,而不是当前方法一.不幸的是,由于validate方法是静态传递的,因此我们无法注入新的处理程序.
  1. Derive a new handler from EPiServer.Web.OutputCacheHandler
  2. Create an alternative method to ValidateOutputCache(...) that still calls OutputCacheHandler.UseOutputCache(...) but ignores the cache version number
  3. Derive a new attribute from ContentOutputCacheAttribute
  4. Override the method 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.

例如

public override void OnResultExecuting(ResultExecutingContext filterContext)
{        
    // Rest of method
    filterContext.HttpContext.Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(CustomOutputCacheHandler.CustomValidateOutputCache), (object) tuple);
}

  1. 使用新属性代替 [ContentOutputCache]

这篇关于停止EPiServer在发布时清除输出缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆