Skip to content Skip to sidebar Skip to footer

Browser Caching Issues In Flask

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 in as.

Solution 1:

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

@app.after_requestdefadd_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

Solution 2:

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

Cache-Control:no-cache,no-storePragma: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

Post a Comment for "Browser Caching Issues In Flask"