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
- Set Up Flask-Caching
- Cache a View with cached
- Memoize Expensive Functions
- Invalidate and Expire Cache Entries