unable to set cache expiration on in app.yaml for

2019-02-20 03:27发布

In my GAE app I am serving static content as follows (those are my entries in my app.yaml file):

handlers:
- url: /css
  static_dir: static/css
  expiration: "10m"

- url: /js
  static_dir: static/js
  expiration: "10m"

Despite the information available here: https://developers.google.com/appengine/docs/python/config/appconfig#expiration the content is never cached in the browser regardless whether I use the dev server or upload my app.

I am using Chrome and the request header is:

cache-control:max-age=0

and the response headers are:

cache-control:no-cache, must-revalidate
pragma:no-cache
server:Google Frontend
status:304 Not Modified

As per some answers I was able to find, I tested this both with being logged in and out into my google admin account and nothing changes.

Any help on this would be greatly appreciated. Many thanks!

Response headers I get when logged out of my admin account:

date:Fri, 25 Apr 2014 09:54:44 GMT
etag:"lhoIow"
server:Google Frontend
status:304 Not Modified
version:HTTP/1.1

2条回答
▲ chillily
2楼-- · 2019-02-20 04:05

GAE should work fine with 10m value. Most probably that was because you were signed in with your google admin account. GAE returns no-cache for such accounts. Trying opening the same page in an incognito returns proper cache expiry times.

By default GAE sets cache to 10 minutes, so even if you didn't set any expiry - you should see 10 minutes instead of no-cache.

查看更多
三岁会撩人
3楼-- · 2019-02-20 04:07

After the hint from Martijn above I changed expiration values in my app.yaml to:

handlers:

- url: /css

  static_dir: static/css

  expiration: "0d 10m"



- url: /js

  static_dir: static/js

  expiration: "0d 10m"

Now everything works as expected and the I get the following headers in response:

cache-control:public, max-age=600
content-encoding:gzip

Everything seems to work as expected now.

查看更多
登录 后发表回答