简体   繁体   English

缓存POST:什么是合适的标头?

[英]Caching POST: What are appropriate headers?

From RFC 2616 , section 9.5 (POST): 根据RFC 2616第9.5节(POST):

Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. 除非响应包含适当的Cache-Control或Expires标头字段,否则对此方法的响应不可缓存。

What are appropriate headers ? 什么是合适的标题

Background: The server responds with the following headers, and I am worried that the response may be cached. 背景:服务器使用以下标头进行响应,我担心响应可能会被缓存。 Example response headers: 响应头示例:

Cache-Control:max-age=2592000, public
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:22
Content-Type:application/json
Date:Sun, 20 May 2012 13:46:06 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=15, max=100
Pragma:no-cache
Server:Apache/2.2.22 (Amazon)
Vary:Accept-Encoding,User-Agent
X-Powered-By:PHP/5.3.13

The post request is made from JavaScript using jQuery's $.ajax function with cache set to false . 使用jQuery的$.ajax函数从JavaScript发出发布请求,并将cache设置为false However, jQuery ignores that option. 但是,jQuery忽略了该选项。 Quote from its documention as of 2012-05-20 CEST : 引用自其截至2012-05-20 CEST的文献

Pages fetched with POST are never cached, so the cache and ifModified options in jQuery.ajaxSetup() have no effect on these requests. 用POST获取的页面永远不会被缓存,因此jQuery.ajaxSetup()中的缓存和ifModified选项对这些请求没有影响。

Update 更新资料

Could it be that jQuery's documentation is wrong? 可能是jQuery的文档错误吗? See my related thread in the jQuery forum . 请参阅jQuery论坛中的相关主题

This header, 这个头

Cache-Control:max-age=2592000, public

Will cause the response to be cached by any intermediary for a long time. 将导致响应被任何中介长时间存储。 The response is a bit confused because pragma: no-cache contradicts this. 响应有点混乱,因为pragma: no-cache与此矛盾。 However, I would suspect that it is only certain older proxies that would even look at the pragma header. 但是,我怀疑只是某些较老的代理甚至会查看编译指示头。

jQuery has no control over intermediary caches so there may exist some public cache, at your ISP for example, that is caching the response. jQuery无法控制中间缓存,因此,例如在您的ISP处可能存在一些公共缓存,用于缓存响应。

Seems confusing, Cache-Control looks like enabling cache, while Pragma and Expires seems to disable cache at the same time. 似乎令人困惑, Cache-Control看起来像启用缓存,而PragmaExpires似乎同时禁用了缓存。 Anyway, HTTP status code should tell exactly whether the request was cached or not. 无论如何,HTTP状态代码应准确告知请求是否已缓存。 200 - not cached, 304 or similar - cached. 200未缓存, 304或类似内容-已缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM