outputcache mvc3只注销了用户缓存

max*_*dbe 6 outputcache asp.net-mvc-3

有没有办法使用OutputCache属性来缓存仅注销用户的结果并重新评估登录用户示例:

我想要什么

[OutputCache(onlycacheanon = true)]
public ActionResult GetPhoto(id){
   var photo = getPhoto(id);
   if(!photo.issecured){
      return photo...
   }
   return getPhotoOnlyIfCurrentUserHasAccess(id);
   //otherwise return default photo so please don't cache me
}
Run Code Online (Sandbox Code Playgroud)

jga*_*fin 8

您可以使用该VaryByCustom物业[OutputCache].

然后重写HttpApplication.GetVaryByCustomString并检查HttpContext.Current.User.IsAuthenticated.

  • "NotAuthed"如果未经过身份验证,则返回或类似(激活缓存)
  • Guid.NewGuid().ToString() 使缓存无效

  • `null`**不会**禁用缓存.我已经在示例项目上尝试了该解决方案,它只是为经过身份验证和未经过身份验证的用户单独缓存... (5认同)