6

尽管这个问题应该是微不足道的,但我没有成功在 web google app engine java 服务器上启用浏览器缓存。

我尝试将这种东西放在我的 appengine-web.xml 中:

<static-files>
  <include path="/**.cache.**" expiration="365d" />
...

但是当我查看响应头时,我在本地找到了这个:

Content-Length: 196084
Cache-Control: public, max-age=31536000
Expires: Fri, 10 Jan 2014 19:40:45 GMT
Content-Type: image/png
Last-Modified: Tue, 18 Dec 2012 21:41:22 GMT
Server: Jetty(6.1.x)

这很好......但这在生产环境中:

HTTP/1.1 304 Not Modified
ETag: "RV4Bpg"
X-AppEngine-Estimated-CPM-US-Dollars: $0.000000
X-AppEngine-Resource-Usage: ms=109 cpu_ms=0
Date: Thu, 10 Jan 2013 19:41:20 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, must-revalidate
Server: Google Frontend

这绝对不是我想要的:(

任何的想法 ?我错过了什么?

[编辑] 对于尚未下载的内容,我的浏览器会收到以下标题:

HTTP/1.1 200 OK
ETag: "RV4Bpg"
Date: Fri, 11 Jan 2013 12:50:50 GMT
Expires: Sat, 11 Jan 2014 12:50:50 GMT
Cache-Control: public, max-age=31536000
X-AppEngine-Estimated-CPM-US-Dollars: $0.000000
X-AppEngine-Resource-Usage: ms=3 cpu_ms=0
Date: Fri, 11 Jan 2013 12:50:50 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, must-revalidate
Content-Type: image/png
Server: Google Frontend
Content-Length: 196084
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
X-RBT-Optimized-By: eu-dcc-sh02 (RiOS 6.5.5b) SC

一个 ETag 和几个相互矛盾的 'Expires' 和 'Cache-Control' ... 有几种方法可以配置缓存策略?它可能来自我的 ISP 吗?还是代理?

4

2 回答 2

9

当您以管理员身份登录 Google App Engine 应用程序时:

  1. X-AppEngine-*包括您的问题中显示的标题。
  2. 包含标Cache-Control: no-cache, must-revalidate头,因为X-AppEngine-*标头是私有的,不得缓存。

这隐藏在https://developers.google.com/appengine/docs/python/runtime#Responses的 Responses 部分的末尾,它说:

带有资源使用统计信息的响应将不可缓存。

于 2013-02-10T01:18:10.207 回答
2

是,Cache-Control已关闭,因为回复是 HTTP 304。

问题是您的浏览器保存了 ETag:http ://en.wikipedia.org/wiki/HTTP_ETag

现在,对于相同 url/内容的每个请求,浏览器都会提供带有 HTTP 304 Not Modified 的 ETag 和 GAE 回复。

尝试更改此 url 的资源(图像),检查您尚未在此浏览器中加载的另一个 url 或完全使用其他浏览器或计算机。

此外,这是相关的:什么优先:ETag 或 Last-Modified HTTP 标头?

于 2013-01-10T21:57:08.260 回答