2010-10-10 83 views
0

下午好, 我需要我的Servlet的结果总是被浏览器缓存。试图放置像http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js一样的头文件,但结果仍然不是来自浏览器缓存(使用FireBug进行测试)。GAE&响应缓存

我的代码:

response.setContentType("text/javascript"); 
    response.setHeader("Last-Modified", "Mon, 15 Feb 2010 23:30:12 GMT"); 
    response.setHeader("Date", "Tue, 28 Sep 2010 19:45:24 GMT"); 
    response.setHeader("Expires", "Wed, 28 Sep 2021 19:45:24 GMT"); 
    response.setHeader("Vary", "Accept-Encoding"); 
    response.setHeader("X-Content-Type-Options", "nosniff"); 
    response.setHeader("Cache-Control", "public, max-age=31536000"); 
    response.setHeader("Age", "36"); 

我的头(萤火虫):

HTTP/1.1 200 OK 
Content-Type: text/javascript; charset=UTF-8 
Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT 
Date: Sun, 10 Oct 2010 14:40:49 GMT 
Expires: Mon, 10 Oct 2011 14:40:49 GMT 
Vary: Accept-Encoding 
X-Content-Type-Options: nosniff 
Server: sffe 
Content-Encoding: gzip 
Cache-Control: public, max-age=31536000 
Content-Length: 46401 
Age: 2 

Googleapis标题:

HTTP/1.1 200 OK 
Content-Type: text/javascript; charset=utf-8 
Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT 
Expires: Wed, 28 Sep 2021 19:45:24 GMT 
Vary: Accept-Encoding 
X-Content-Type-Options: nosniff 
Cache-Control: public, max-age=31536000 
Age: 36 
Content-Encoding: gzip 
Date: Sun, 10 Oct 2010 14:32:06 GMT 
Server: Google Frontend 
Content-Length: 36838 

所有标头是一样的,但不同的顺序(即使代码 - 不应该,显然GAE颠倒了顺序)。 可能是什么问题? 谢谢。

回答

2

订购并不重要。你有问题吗?从理论上讲,如果GAE使用的servlet容器使用HashMap在提交响应之前存储标题,并且您的本地servlet容器为LinkedHashMapList<Pair>,则可能会发生这种情况。

至于响应缓存,您至少需要一个远期的Expires标头以及有效的ETagLast-Modified标头。没有必要使用Cache-ControlAge

+0

我无法更改顺序。因此,输出中的标题几乎完全相同,但由于某种原因,FireFox拒绝缓存脚本。一个工作示例:http://static.metabus.ru/js/join.js?jquery-1.4.2.min.js,jquery.mousewheel-3.0.js当使用FireBug更新此URL时,每次都可以看到该浏览器加载数据。但每次都从缓存中取得http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js。 – chardex 2010-10-10 15:01:32

+0

它在这里得到正确的缓存。你的问题在别的地方。你不是在使用Ctrl + F5进行“硬刷新”吗? – BalusC 2010-10-10 15:13:13

+0

不,只是F5。你如何确定结果被正确缓存? – chardex 2010-10-10 15:27:15

1

改为使用addHeader。 setHeader()覆盖之前设置的值