最佳设置HTTP缓存头和服务器PARAMS在ASP.Net MVC和IIS 7.5 [英] Setting optimum http caching headers and server params in ASP.Net MVC and IIS 7.5
问题描述
我有一个ASP.Net网站(恰好是MVC,但是我们在这里不会有关)与我想缓存真的很好了几页。
I have an ASP.Net site (happens to be MVC, but that's not relevant here) with a few pages I'd like cached really well.
我特别想达成的目标:
- 输出缓存在服务器上2小时。
- 如果在服务器上修改文件内容,即输出缓存应该被刷新该页面
- 在浏览器中缓存的10分钟(即不要问服务器,如果它是新鲜的)
- 当浏览器确实让一个实际的后续请求,我想它使用ETag,使服务器可以返回一个304,如果不修改
(注意 - 上面的时间值表示的例子只)
(note - time values above are indicative examples only)
- 1),2)我可以Response.Cache.SetCacheability实现(HttpCacheability.Server)
- 我知道3)可以使用最大年龄和缓存控制来实现:私人
- 我能发出与Response.Cache.SetETagFromFileDependencies)的ETag(;
但我似乎无法得到的所有的这些东西一起工作。下面是我有:
but I can't seem to get all of these things to work together. Here's what I have:
Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetETagFromFileDependencies();
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetMaxAge(TimeSpan.FromSeconds(60 * 10));
是我想尽可能的情况?特别是:
Is the scenario I want possible? In particular:
- 浏览器可以做到既3),4)这样呢?当它在本地缓存过期之后的Firefox发出新的请求时,它确实向服务器发送与之前的响应ETAG,但我得到一个200响应。
- 设置类似上面的变量,在那里我会设置输出缓存的时间?
感谢您的任何提示!
推荐答案
我不知道,如果你已经解决了这个问题,但(几个月后...),但这个的应的是可能的。
I'm not sure if you've solved this problem yet (several months later...), but this should be possible.
SetMaxAge
应该设置的guarranteed保鲜时间。如果你还发了ETag,你必须满足3及4.要求1安培; 2可以正交与任何服务器端缓存机制来解决您使用。我从来没有使用ASP.NET服务器端缓存这样,但它几乎肯定可以
SetMaxAge
should set the amount of "guarranteed" fresh time. If you additionally send an ETag, you'll have satisfied 3 & 4. Requirements 1 & 2 can be solved orthogonally with whatever server-side caching mechanism you use: I've never used ASP.NET server-side cache like this, but it's almost certainly possible.
我想从你的回答删除多余的头,如 SetRevalidation
- 为什么这是必要的。
I'd remove extraneous headers from your responses such as SetRevalidation
- why would this be necessary?
这篇关于最佳设置HTTP缓存头和服务器PARAMS在ASP.Net MVC和IIS 7.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!