1

This is what I have tried from Python/tornadoweb:

    self.set_header("Cache-Control","no-cache, must-revalidate, max-age=0")
    self.set_header("Expires","Mon, 26 Jul 1997 05:00:00 GMT")

This is what I see from firebug when I first load the page:

Cache-Control   no-cache, must-revalidate, max-age=0
Content-Length  1715
Content-Type    text/html; charset=UTF-8
Etag    "e55dc7115d80aa09b470510ababb3515706f4a61"
Expires Mon, 26 Jul 1997 05:00:00 GMT
Server  TornadoServer/2.3
Set-Cookie  xsfr=5b7f3cf86c2e4537acd1bb1749484a5b; Path=/

And yet, when I press BACK button to go back to the original URL, I get a cached version of the page! The page is not re-fetched from the server. The result is that it contains invalid hidden form values. No matter how the user fills in the form, it cannot be processed.

The problem can be reproduced on firefox and chrome, but not from internet explorer.

So, how to force firefox and chrome to disable the cache and reload the page whenever the back button is pressed?

4

1 回答 1

0

我不知道你是否解决了这个问题,但我昨晚遇到了同样的问题。这个答案在一定程度上帮助了我。我通过设置标题和清除用户 cookie 解决了这个问题。

这是我所做的要点:

class BaseHandler(tornado.web.RequestHandler):

    def set_default_headers(self):
        self.set_header('Cache-Control', 'no-cache, no-store, must-revalidate')
        self.set_header('Pragma', 'no-cache')
        self.set_header('Expires', '0')

现在 SignOut 处理程序:

class SignOut(BaseHandler):

    def get(self):
        self.clear_cookie("user")
        self.redirect('/')

“用户”是 cookie 集的名称。

于 2016-10-06T09:54:26.017 回答