原文:http://librelist.com/browser/flask/2011/8/8/add-no-cache-to-response/#952cc027cf22800312168250e59bade4

 

Method 1:

@app.route('/nocache')
def something_not_cached():
    resp = make_response(render_template(...))
    resp.cache_control.no_cache = True
    return resp

Or you write a decorator:

@app.route('/nocache')
@nocache
def something_not_cached():
    return render_template(...)

And here is the decorator:

from flask import make_response
from functools import update_wrapper

def nocache(f):
    def new_func(*args, **kwargs):
        resp = make_response(f(*args, **kwargs))
        resp.cache_control.no_cache = True
        return resp
    return update_wrapper(new_func, f)

resp.cache_control is an accessor for the Cache-Control header, you can
also modify the header directly:

resp.headers['Cache-Control'] = 'no-cache'

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2021-05-27
相关资源
相似解决方案