我正在尝试缓存 servlet 响应,但不知何故它不起作用(每次刷新页面时,Firebug 都会给我 200 OK)。这是我在 servlet 中添加的代码:
response.setContentType("application/javascript");
long now = System.currentTimeMillis();
response.setCharacterEncoding("UTF-8");
response.setDateHeader("Last-Modified", 0);
response.addHeader("Cache-Control", "max-age=5184000");
response.setDateHeader("Expires", now + 5184000 * 1000);
response.addHeader("Vary", "Host");
我现在也尝试过 withsetHeader
和 with Last-Modified
。
似乎没有任何效果。有任何想法吗?
谢谢
这就是萤火虫向我显示响应/请求标头的方式(当资源应该从缓存中获取但不是时):
Response Headersview source
Cache-Control max-age=5184000
Connection Keep-Alive
Content-Type application/javascript;charset=UTF-8
Date Thu, 21 Mar 2013 09:53:48 GMT
Expires Sun, 31 Mar 2013 16:51:01 GMT
Keep-Alive timeout=15, max=99
Request Headersview source
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control max-age=0