Disabling caching in Flask Disabling caching in Flask python python

Disabling caching in Flask


OK,

finally it worked with this:

@app.after_requestdef add_header(r):    """    Add headers to both force latest IE rendering engine or Chrome Frame,    and also to cache the rendered page for 10 minutes.    """    r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"    r.headers["Pragma"] = "no-cache"    r.headers["Expires"] = "0"    r.headers['Cache-Control'] = 'public, max-age=0'    return r

If you add this, this function will called after each request done. Please,see here

I would be happy, if anyone could explain me why this headers overwriting did not work from the page handler?

Thank you.


If you have always the same problem, that Flask didn't see the updates in JS and CSS files, that because by default, Flask has as max-age value 12 hours. You can set it to 0 to resolve the problem like this:

app = Flask(__name__)app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

Refer to its documentation for details.


A combination ofapp.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 in the python file

andhard reload (command + shift + R) of the chrome browser worked for me as it seems Chrome caches the static files