【发布时间】:2016-05-07 14:50:05
【问题描述】:
作为 DonutCache 的替代方案,是否有人发现以下输出缓存方法存在任何问题。它似乎可以在不暴露任何用户数据的情况下工作,并根据时间戳测试为每个人正确缓存页面,这是我最关心的问题。我只是想先覆盖我的基础,然后再在我的实时网站上实施它。
在 Glogal.asax.cs 中
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (arg == "User")
{
if (context.User.Identity.Name != "")
{
return "User=" + context.User.Identity.Name;
}
else
{
return "User=Guest";
}
}
return base.GetVaryByCustomString(context, arg);
}
在 Web.config 中
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="HomePage" duration="86400" varyByParam="*" varyByCustom="User" location="Server" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
*n 控制器
[OutputCache(CacheProfile = "HomePage")]
public ActionResult Index()
{
return View();
}
参考解决方案:Output cache per User
【问题讨论】:
标签: c# asp.net outputcache asp.net-mvc-5