过期输出缓存ASP.Net MVC [英] Expire Output Cache ASP.Net MVC
问题描述
我使用的是标准的OutputCache标签在我的MVC应用程序伟大的工程,但我需要迫使它在特定的时间被倾倒。我该如何实现这一目标?这被缓存的页面是从一个非常简单的路线{控制器} / {}页面名称建 - 所以大部分页面是这样的:/页/关于美
I am using the standard outputcache tag in my MVC app which works great but I need to force it to be dumped at certain times. How do I achieve this? The page that gets cached is built from a very simple route {Controller}/{PageName} - so most pages are something like this: /Pages/About-Us
下面是输出缓存标记,是在我的.aspx视图页面的顶部仅仅是明确的:
Here is the output cache tag that is at the top of my .aspx view page just to be clear:
<@ OutputCache Duration="100" VaryByParam="None" %>
因此,在相同的控制器,其中的内容更新我需要倾倒此缓存,甚至这一切对另一个动作 - 这是一个很小的应用程序,所以也不是什么大不了的交易抛售所有缓存项
So in another action on the same controller where content is updated I need to dump this cache, or even all of it - it's a very small app so not a big deal deal to dump all cached items.
推荐答案
请小心使用无与。
- 如果您发送那href=\"http://www.w3.org/Protocols/HTTP/Issues/vary-header.html\">因人而异了解不的发送。
- 如果您发送无,那么对的HTTPHeader 因人而异 是的发送。
- If you send "" then the HttpHeader for Vary is not sent.
- If you send "None" then the HttpHeader for Vary is sent.
我用提琴手来验证此行为。
这似乎对浏览器是否不返回到服务器以检查最新版本产生影响(导致304)。至少在Chrome它。要使用不定=
如果你肯定知道你是不是打算要更新的文件之前已过期。
This seems to have an impact on whether or not the browser goes back to the server to check for latest version (causing a 304). At least in Chrome it does. You want to use Varies=""
if you know for sure you aren't going to want to update the file before it has expired.
我推荐使用不定=
像我一样在<一个href=\"http://stackoverflow.com/questions/486063/what-clever-things-have-you-done-with-an-asp-net-mvc-actionresult\">this帖子。对于我的javascript文件我不希望浏览器回去,使另一个HTTP请求,直到它已过期。 304是不必要的。
I'd recommend using Varies=""
as I did in this post. For my javascript file I dont want the browser going back and making another Http request until it has expired. 304 is unnecessary.
这篇关于过期输出缓存ASP.Net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!