禁止在MVC 3的局部视图缓存 [英] Disable caching on a partial view in MVC 3

查看:163
本文介绍了禁止在MVC 3的局部视图缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个局部视图的问题被缓​​存,当它不应该。这部分视图用于在页面上显示的登录/注销。它使用下面的简单code弄清楚要显示的链接

I have an issue with a partial View being cached when it shouldn't be. This partial View is used to display the Logon/Logoff on a page. It uses the simple code below to figure out which link to display

@if(Request.IsAuthenticated) {    
    <a href="@Url.Action("LogOff", "Account", new { area = "" })">Log Off</a> 
}
else {
    <a href="@Url.Action("LogOn", "Account", new { area = "" })">Log On</a>
}

这部分观点是从我MVC3应用程序的所有页面调用,使用

This partial View is called from with all pages in my MVC3 application, using

@Html.Partial("_HeaderView")  

在我的大多数控制器,我有输出缓存定义的,所以我可以把我的缓存内容的优势。

In most of my controllers, I have the output cache defined, so I can take advantage of caching my content.

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

现在我的问题是,整个页面被缓存的时候我不想局部视图为。这导致错误的行为,其中它有时显示注销时用户没有在等记录是否有缓存所有内容的方式,除了所讨论的局部视图?

Now my issue is that the entire page is being cached when I don't want the partial view to be. This is causing wrong behavior where it sometimes display LogOff is the user is not logged in etc. Is there a way to cache all the content, except for the partial view in question?

推荐答案

您在找什么叫甜甜圈缓存。这里有一个很好的文章,解释它是什么,以及如何使其工作<一个href=\"http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3\">http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3

What you are looking for is called Donut Caching. Here's a great article explaining what it is and how to make it work http://www.devtrends.co.uk/blog/donut-output-caching-in-asp.net-mvc-3

这篇关于禁止在MVC 3的局部视图缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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