0Pricing
Flask Academy · Lesson

Cache a View with cached

Memoize whole responses by URL.

Caching Whole Responses

Some pages cost real work to build. The cached decorator stores the entire response, so repeat visitors get an instant copy.

Apply the Decorator

You add @cache.cached() right above your view function. The first request runs it; later ones replay the stored result.

@app.route("/report")
@cache.cached()
def report():
    return build_report()

All lessons in this course

  1. Set Up Flask-Caching
  2. Cache a View with cached
  3. Memoize Expensive Functions
  4. Invalidate and Expire Cache Entries
← Back to Flask Academy