过期输出缓存 ASP.Net MVC [英] Expire Output Cache ASP.Net MVC

查看:33
本文介绍了过期输出缓存 ASP.Net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 MVC 应用程序中使用了标准 outputcache 标签,它运行良好,但我需要在特定时间强制转储它.我如何实现这一目标?被缓存的页面是从一个非常简单的路由 {Controller}/{PageName} 构建的 - 所以大多数页面是这样的:/Pages/About-Us

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.

推荐答案

小心使用None"与".

Be careful about using "None" vs. "".

  • 如果您发送",则 变化 发送.
  • 如果您发送无",则 变化 发送.
  • If you send "" then the HttpHeader for Vary is not sent.
  • If you send "None" then the HttpHeader for Vary is sent.

我使用 Fiddler 来验证这种行为.

I used Fiddler to verify this behavior.

这似乎会影响浏览器是否会返回服务器检查最新版本(导致 304).至少在 Chrome 中是这样.如果您确定不想在文件过期之前更新文件,您想使用 Varies="".

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.

我建议使用 Varies="",就像我在 这篇文章.对于我的 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屋!

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