简体   繁体   中英

Caching POST: What are appropriate headers?

From RFC 2616 , section 9.5 (POST):

Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields.

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 . However, jQuery ignores that option. Quote from its documention as of 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.

Update

Could it be that jQuery's documentation is wrong? See my related thread in the jQuery forum .

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. 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.

Seems confusing, Cache-Control looks like enabling cache, while Pragma and Expires seems to disable cache at the same time. Anyway, HTTP status code should tell exactly whether the request was cached or not. 200 - not cached, 304 or similar - cached.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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