6

Although this question should be trivial, I didn't success to enable browser caching on web google app engine java server.

I've try to put this kind of thing in my appengine-web.xml:

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

but when I'm looking the response header I find this in local:

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)

Which is fine... but this in production environment:

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

Which is definitively not what I want :(

Any idea ? something I've missed ?

[EDIT] for not yet downloaded content, my browser receive the following header:

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

An ETag and several contradictory 'Expires' and 'Cache-Control' ... Is there several way to configure caching policy ? Could it come from my ISP ? or a proxy ?

Kroc
  • 63
  • 1
  • 7
  • Possible duplicate of [Cache-related HTTP headers are overridden in Servlet response on App Engine](http://stackoverflow.com/questions/14172758/cache-related-http-headers-are-overridden-in-servlet-response-on-app-engine) – icza Dec 09 '14 at 06:45

2 Answers2

9

When you are logged in to a Google App Engine application as an administrator:

  1. The X-AppEngine-* headers shown in your question are included.
  2. The Cache-Control: no-cache, must-revalidate header is included, because the X-AppEngine-* headers are private and must not be cached.

This is hidden at the end of the Responses section at https://developers.google.com/appengine/docs/python/runtime#Responses, which says that:

Responses with resource usage statistics will be made uncacheable.

Carey
  • 1,198
  • 6
  • 11
  • 1
    I had similar problems to those in the questions asked, and I would like to point out that even if you are not logged in as GAE admin (e.g. use Chrome as guest or logging out or something), you can still get 304. In my case I used Chrome, not logged in as GAE admin, had dev tools open, 'Disable cache (while DevTools is open)' was unchecked. Still 304. I found out that the reason was that when hittin cmd + R (or ctrl + R) the browser does not use cache. Try clicking the url field of the browser and hit enter instead, and all those 304's should now be 200 (cache). – stianlp Apr 11 '16 at 08:41
2

Yes, Cache-Control is off because reply is HTTP 304.

The problem is that your browser saved the ETag: http://en.wikipedia.org/wiki/HTTP_ETag

Now for every request for the same url/content, browser provides ETag and GAE replies with HTTP 304 Not Modified.

Try changing the resource (image) at this url, checking another url that you have not yet loaded in this browser or using another browser or computer altogether.

Also, this is relevant: What takes precedence: the ETag or Last-Modified HTTP header?

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks for highliting this ETag feature. For new content, browser receive an ETag and Expires date. (I won't publish header right now because I'm not in similar condition. eg proxy) I'll complete my question. – Kroc Jan 11 '13 at 13:08