I'm seeing the below response from some calls to a webserver:
下面是一些对webserver的响应:
Initial call:
初始调用:
HTTP/1.1 200 OK
Date: Mon, 16 Jan 2012 05:46:49 GMT
X-Powered-By: Servlet/2.5 JSP/2.1
Content-Type: text/plain
Content-Length: 78
Content-Encoding: gzip
Etag: "pv2052dae8634d971149a927231e3ceddf"
Cache-Control: no-cache
X-PvInfo: [S10202.C6191.A6057.RA6008.G182D.U3FAE8760].[OT/plaintext.OG/documents]
Vary: Accept-Encoding
Set-Cookie: JSESSIONID=l9pLPT5J1tpgK19Fq2qlT0F15ryByWDLgVLz16ffWPm4qQp6nzzx!-518520380; path=/; HttpOnly
DST=rd319o00000000000000000000ffffac16018bo8200; path=/
Connection: close
Subsequent calls:
后续调用:
HTTP/1.1 304 Not Modified
Date: Mon, 16 Jan 2012 05:48:43 GMT
Connection: close
Etag: "pv2052dae8634d971149a927231e3ceddf"
Cache-Control: no-cache
Vary: Accept-Encoding
What I'm unclear about is that both calls return a Cache-Control: no-cache
directive to the browser.
我不清楚的是,这两个调用都向浏览器返回一个Cache-Control: no-cache指令。
However, the second call also returns a 304 Not Modified
.
但是,第二个调用也返回一个未修改的304。
Where does the server expect the page to serve the data from, given that it's been instructed not to cache the earlier response?
考虑到已经指示页面不缓存早期响应,服务器期望页面从何处提供数据?
Interestingly, I do see the response served in the browser, so the browser appears to have cached the response, despite the no-cache directive. Why?
有趣的是,我确实在浏览器中看到了响应,因此浏览器似乎已经缓存了响应,尽管没有缓存指令。为什么?
1 个解决方案
#1
16
A response with Cache-Control: no-cache
does not mean that the response must not be stored at the client at all, instead it means:
带有Cache-Control的响应:无cache并不意味着响应不能存储在客户端,而是意味着:
If the no-cache directive does not specify a field-name, then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server. This allows an origin server to prevent caching even by caches that have been configured to return stale responses to client requests.
如果无缓存指令没有指定字段名,那么在没有成功地与源服务器重新验证之前,缓存不能使用响应来满足后续请求。这允许源服务器防止缓存,即使缓存被配置为将陈旧的响应返回给客户端请求。
So the client is allowed to store the response in the local cache but it needs to revalidate the response by the origin server. If the server says that the response stored in the client’s cache is still valid (i. e. 304 response), the client is allowed to use the stored response to satisfy the request.
因此,客户端可以将响应存储在本地缓存中,但它需要重新验证源服务器的响应。如果服务器说存储在客户端缓存中的响应仍然有效(即。304响应),允许客户端使用存储的响应来满足请求。
#1
16
A response with Cache-Control: no-cache
does not mean that the response must not be stored at the client at all, instead it means:
带有Cache-Control的响应:无cache并不意味着响应不能存储在客户端,而是意味着:
If the no-cache directive does not specify a field-name, then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server. This allows an origin server to prevent caching even by caches that have been configured to return stale responses to client requests.
如果无缓存指令没有指定字段名,那么在没有成功地与源服务器重新验证之前,缓存不能使用响应来满足后续请求。这允许源服务器防止缓存,即使缓存被配置为将陈旧的响应返回给客户端请求。
So the client is allowed to store the response in the local cache but it needs to revalidate the response by the origin server. If the server says that the response stored in the client’s cache is still valid (i. e. 304 response), the client is allowed to use the stored response to satisfy the request.
因此,客户端可以将响应存储在本地缓存中,但它需要重新验证源服务器的响应。如果服务器说存储在客户端缓存中的响应仍然有效(即。304响应),允许客户端使用存储的响应来满足请求。