我正在学习缓存以及如何管理它。
我可以看到,当我打开网站页面时,静态内容(如图像,css文件,js文件)会存储在临时文件夹中。但是现在当我在响应头中添加这些属性时,我看不到缓存行为的任何变化。
所有内容都像以前一样存储。即使我在js文件中进行了一些更改,我也看不到要获取的新js文件。浏览器使用具有过时内容的相同旧js文件。
我做错了什么。
我在JSP文件中添加的逻辑:
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP1.1.
response.setDateHeader("Expires", 0); // Proxies.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
在这些变化之后:
响应标头
Cache-Control:no-cache, no-store, must-revalidate
Content-Language:en-US
Content-Length:3333
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Dec 2014 11:48:37 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:no-cache
Server:WebSphere Application Server/8.0
X-Powered-By:Servlet/3.0
在这些变化之前:
响应标头
Content-Language:en-US
Content-Length:6788
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Dec 2014 11:50:10 GMT
Server:WebSphere Application Server/8.0
X-Powered-By:Servlet/3.0
我只是想知道如何验证这些标头是否正常工作。任何帮助将不胜感激。
答案 0 :(得分:1)
在Chrome中安装LiveHTTPHeaders,您可以在页面中看到所有标题。你也可以这么做,并使用像tcpdump或Wireshark这样的pcap工具来查看请求的数据包并查看标题。
答案 1 :(得分:1)
使用curl
:
curl -I "URL"
-I
标志将显示标题。