没有深入研究,简单做一下记录。
HTTP/1.0的时候Pragma、Expires两个缓存的响应头。(大小写无所谓)
HTTP/1.1的时候添加一个新的响应头Cache-control。(大小写无所谓)
使用方式:
控制浏览器不要缓存:
response.setDateHeader("Expires", -1);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-control", "no-cache");
控制浏览器使用缓存:
response.setDateHeader("Expires", System.currentTimeMillis()+1000*60*60*24); //24小时
response.setHeader("Cache-control", "max-age=60"); //60秒(优先级更高)
如果三种控制缓存的方式同事存在的话,Cache-control优先级更高。如果只有HTTP/1.0的控制缓存的头存在,Pragma优先级更高。由于历史原因,设置不读取缓存的时候三者都需要设置。
注意:不读取缓存不是不进行缓存。
参考文章:http://www.cnblogs.com/vajoy/p/5341664.html
链接中对缓存进行了举例和详细的总结。 |