2

I read this post https://stackoverflow.com/a/23115561/1765681 . It works but it make global. So my admin page get cached. And I don't want that.

For example. If I want to set cache control only to this:

@app.route('/')
def list_posts():
    entries = db_session.query(Entry).order_by(desc(Entry.id)).limit(5)
    return render_template('list.html', entries=entries)

what should I do?

Community
  • 1
  • 1
fpilee
  • 1,918
  • 2
  • 22
  • 38

1 Answers1

3

Capture the response from render_template, and then adjust it as necessary.

Like this:

#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

References:

Ori
  • 4,132
  • 1
  • 25
  • 27
Robᵩ
  • 163,533
  • 20
  • 239
  • 308