Browser caching issues in flask

后端 未结 2 1690
南旧
南旧 2020-12-05 01:13

I have built a website using flask (www.csppdb.com). Sometimes when I log in as one user, log out, then login as another user I still see pages from the first user I logged

相关标签:
2条回答
  • 2020-12-05 01:34

    To stop browser caching on these sort of pages you need to set some HTTP response headers.

    Cache-Control: no-cache, no-store
    Pragma: no-cache
    

    Once you do this then the browser wont cache those pages. I dont know how to do this with "flask" so I will leave that as an exercise for you :)

    This question shows how to add a response header Flask/Werkzeug how to attach HTTP content-length header to file download

    0 讨论(0)
  • 2020-12-05 01:36

    Setting the cache to be max-age=0 fixed it.

    @app.after_request
    def add_header(response):
        """
        Add headers to both force latest IE rendering engine or Chrome Frame,
        and also to cache the rendered page for 10 minutes.
        """
        response.headers['X-UA-Compatible'] = 'IE=Edge,chrome=1'
        response.headers['Cache-Control'] = 'public, max-age=0'
        return response
    
    0 讨论(0)
提交回复
热议问题