简介
- 一种是浏览器访问 nginx,浏览器 Cache
- 另一种是 nginx 访问后端,nginx 自己 Cache
响应头字段说明
Cache-Control: public, max-age=51600
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Date: Tue, 05 Feb 2019 14:28:26 GMT
Expires: Wed, 06 Feb 2019 04:48:26 GMT
Last-Modified: Tue, 05 Feb 2019 14:06:57 GMT
Server: nginx/1.13.9
Transfer-Encoding: chunked
X-Powered-By: PHP/7.1.23
Date 的意思是服务器发送消息的时间
Expires 表示过期时间
-
当expire 为负时,会在响应头增加Cache-Control: no-cache;
-
当为正或者0时,就表示Cache-Control: max-age=指定的时间(秒);
-
浏览器可以通过两种方式来判断缓存文件是否被更新了,一种是 If-Modified-Since ,浏览器通过发送If-Modified-Since 头,带上「上一次请求获得的修改时间,(在Last-Modified头里)」发送到服务器,服务器会判断这个时间之后文件有没有改变,如果没有改变返回状态值304,如果有返回新文件,状态值200 。
<