Preventing page caching in Google App Engine

2019-04-02 22:38发布

When a user of my GAE app clicks the back button, I need to prevent them from seeing a cached version of the page - that is, I need the python get or post code for that url to be run.

3条回答
Ridiculous、
2楼-- · 2019-04-02 23:01

The answer provided by chachan would not work across all browsers. A more complete answer could be found in this answer. Basically, you would need to set all these headers:

<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

to tell the browser to always fetch the page from the server.

查看更多
看我几分像从前
3楼-- · 2019-04-02 23:04

Sometimes setting the cache in meta tags is not what you are looking for and setting the http header is more convenient. This you can do quite easily in Python:

self.response.headers["Pragma"]="no-cache"

self.response.headers["Cache-Control"]="no-cache, no-store, must-revalidate, pre-check=0, post-check=0"

self.response.headers["Expires"]="Thu, 01 Dec 1994 16:00:00"

Goole has a great document on how to use the Response Class here: http://code.google.com/appengine/docs/python/tools/webapp/responseclass.html

查看更多
再贱就再见
4楼-- · 2019-04-02 23:19

Seems like this question isn't related with Google App Engine at all. Although, I found this:

<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate"> 

Hope that help you.

查看更多
登录 后发表回答