相关疑难解决方法(0)

如何使用 ASP.NET MVC 4.0 DonutOutputCache VaryByCustom 使缓存失效

我正在为我的 ASP.NET 应用程序使用 DevTrends.MvcDonutCaching 包,它运行良好。我目前遇到的一个问题是使我为子操作设置的 VaryByCustom 缓存无效。

这是我用于 VaryByCustom 设置的一些代码:

public override string GetVaryByCustomString(HttpContext context, string arg)
{
  if (arg == "userlogin" && context.User.Identity.IsAuthenticated)
  {
     return "UserLogin=" + context.User.Identity.Name;
  }

  return base.GetVaryByCustomString(context, arg);
}
Run Code Online (Sandbox Code Playgroud)

我的动作就是这样装饰的:

[Authorize]
[DonutOutputCache(Duration = 3600, VaryByCustom = "userlogin")]
public ActionResult UserProfile()
{ ... }
Run Code Online (Sandbox Code Playgroud)

这就是我试图清理该缓存的方式(我也尝试过没有任何参数和“用户登录”,但这些都不起作用:

OutputCacheManager om = new OutputCacheManager();
om.RemoveItem("Customer", "UserProfile", new { UserLogin = User.Identity.Name });
Run Code Online (Sandbox Code Playgroud)

那是剃刀视图部分:

<div id="cabinetMain">
 @{Html.RenderAction("UserProfile", true);}
</div>
Run Code Online (Sandbox Code Playgroud)

任何帮助都感激不尽。

谢谢。

c# asp.net caching asp.net-mvc-4

3
推荐指数
1
解决办法
1456
查看次数

标签 统计

asp.net ×1

asp.net-mvc-4 ×1

c# ×1

caching ×1