防止Google App Engine页面缓存

0 投票
3 回答
2617 浏览
提问于 2025-04-17 13:03

当我的GAE应用的用户点击返回按钮时,我需要阻止他们看到页面的缓存版本。也就是说,我需要让这个网址的python getpost 代码重新运行。

3 个回答

2

看起来这个问题和谷歌应用引擎完全没有关系。不过,我找到了一些东西:

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

希望这些对你有帮助。

3

有时候,在网页的元标签里设置缓存并不是你想要的,直接设置HTTP头信息会更方便。你可以很简单地在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"

谷歌有一份很棒的文档,介绍如何使用响应类,你可以在这里查看: http://code.google.com/appengine/docs/python/tools/webapp/responseclass.html

7

chachan提供的答案在所有浏览器上可能都不适用。你可以在这个链接找到更完整的答案。简单来说,你需要设置这些头信息:

<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">

这样可以告诉浏览器每次都从服务器获取页面。

撰写回答