0

我有一个名为“列表”的控制器/操作。此方法具有内置的属性

[OutputCache(Duration = 3600, VaryByParam = "*")]

此操作具有 3600 秒的缓存,因为从数据库加载数据并且每 1 小时(更多/更少)更改一次。

问题出在 Layout.cshtml 上,因为我的主布局(它的主页面)在标题顶部栏显示用户名(如果已通过身份验证的用户)或在用户未通过身份验证时显示静态文本用户。请看下面的代码:

@Html.Raw(WebSecurity.IsAuthenticated ?WebSecurity.CurrentUserName:“用户”)

当任何人通过身份验证时,页面上第一次访问的名称缓存完成,然后所有用户,经过身份验证或未经过身份验证,请参见标题顶部栏上的第一个经过身份验证的用户的用户名。这真是太糟了!

我以为不会做layout.cshtml缓存,只有Controller/Action指定的数据。

我该如何解决?

我不喜欢删除 OutputCache,因为它对我来说非常重要。标题顶部栏对所有用户都是通用的,因为它具有内置的布局页面。

4

1 回答 1

1

I think what you are trying to achieve is Donut Caching, caching all the page except a section. I'm not sure whether MVC supports this (MVC 3 - no). There is an open source available DevTrends.MvcDonutCaching that 'll help you.

于 2012-09-13T16:15:20.267 回答