php 什么是 Pragma 标头?缓存页面.. 和 IE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11992946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the Pragma Header? Caching pages.. and IE
提问by Parris
So I am sending a header in php to cache my page (this integrates into our "CDN" (contendo/akamai) as well). I always use this pragma: cache header, I've seen various examples use it as well; however, I just checked fiddler to test traffic for this .net application we developed and it says:
所以我在 php 中发送一个标头来缓存我的页面(这也集成到我们的“CDN”(contendo/akamai)中)。我总是使用这个 pragma: cache header,我见过各种例子也使用它;但是,我只是检查了 fiddler 来测试我们开发的这个 .net 应用程序的流量,它说:
Legacy Pragma Header is present: cache !! Warning IE supports only an EXACT match of "Pragma: no-cache". IE will ignore the Pragma header if any other values are present. ...
Legacy Pragma Header is present: cache !! Warning IE supports only an EXACT match of "Pragma: no-cache". IE will ignore the Pragma header if any other values are present. ...
I suppose that is ok. The rest of the response seems fine and to my specs. Here is my code:
我想那没问题。其余的响应似乎很好,符合我的规格。这是我的代码:
function headers_for_page_cache($cache_length=600){
$cache_expire_date = gmdate("D, d M Y H:i:s", time() + $cache_length);
header("Expires: $cache_expire_date");
header("Pragma: cache");
header("Cache-Control: max-age=$cache_length");
header("User-Cache-Control: max-age=$cache_length");
}
The question is does this matter? What does the pragma header even do? Do I need it? I checked the HTTP header spec documentation and it said it is implementation specific and the only Pragma that is enforced is "Pragma: no-cache".
问题是这有关系吗?pragma 标头甚至做什么?我需要吗?我检查了 HTTP 标头规范文档,它说它是特定于实现的,唯一强制执行的 Pragma 是“Pragma: no-cache”。
Is this the best choice of headers to cache for a specific amount of time?
这是在特定时间内缓存的标头的最佳选择吗?
回答by raidenace
In a very simplified form, Pragma:no-cache or Pragma:cacheare now "almost" obsolete ways of passing caching instructions to client implementations, specifically browers and proxies. The way the client implementation responds to Pragma headers vary which is why the specification says it is implementation specific.
以非常简化的形式,Pragma:no-cache or Pragma:cache现在“几乎”是将缓存指令传递给客户端实现(特别是浏览器和代理)的过时方式。客户端实现响应 Pragma 标头的方式各不相同,这就是为什么规范说它是特定于实现的。
The more modern way of Cache-controlis what you can safely depend on, as almost all client implementations follow it rigidly.
更现代的方式Cache-control是您可以放心依赖的方式,因为几乎所有客户端实现都严格遵循它。
Also, if you have both Cache-controland Pragmaset for the same instruction, say caching, then Cache-controltakes precedence.
此外,如果您同时拥有Cache-control并Pragma为同一指令设置,则说缓存,则Cache-control优先。
This is an excellentarticle about everything related to Caching and I think it makes a very interesting and useful read: http://www.mnot.net/cache_docs/
这是一篇关于与缓存相关的一切的优秀文章,我认为它是一个非常有趣和有用的阅读:http: //www.mnot.net/cache_docs/

