我读了这篇文章 https://stackoverflow.com/a/23115561/1765681 .它有效,但它使全局。所以我的管理页面被缓存了。我不想那样。
例如。如果我只想为此设置缓存控制:
@app.route('/')
def list_posts():
entries = db_session.query(Entry).order_by(desc(Entry.id)).limit(5)
return render_template('list.html', entries=entries)
我该怎么办?
请您参考如下方法:
捕获来自 render_template 的响应,然后根据需要进行调整。
像这样:
#UNTESTED
@app.route('/')
def list_posts():
entries = db_session.query(Entry).order_by(desc(Entry.id)).limit(5)
resp = make_response(render_template('list.html', entries=entries))
resp.cache_control.max_age = 300
return resp
引用资料:
