0

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.

Tr3y
  • 191
  • 4
  • 11
  • Thanks for all answers! I asked this question primarily because internet documentation suggested that setting Pragma, etc is ineffective and that a more powerful (unspecified) server-side solution would be necessary. Are these solutions very reliable? – Tr3y Feb 16 '12 at 01:01
  • Well, the number of upvotes in the answer that I linked seems to show that it's reliable. ;) I also have a similar requirement in my app (I have a REST API that must not be cached by the client browser) so I followed the recommendation in the answer, and so far it works for me. I would suggest you try it by yourself, and verify that it works by monitoring the logs in your app engine dashboard. Cached page will not show up as requests at all, or will show up but with HTTP Status 304 (Not Modified) as its response. – Ibrahim Arief Feb 16 '12 at 07:01

3 Answers3

7

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.

Community
  • 1
  • 1
Ibrahim Arief
  • 7,840
  • 4
  • 32
  • 53
3

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

Community
  • 1
  • 1
2

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.

chachan
  • 2,134
  • 1
  • 25
  • 39