Flask-Caching

Flask-Caching is an extension to Flask that adds caching support for various backends to any Flask application. By running on top of cachelib it supports all of werkzeug’s original caching backends through a uniformed API. It is also possible to develop your own caching backend by subclassing BaseCache class.

from flask import Flask
from flask_caching import Cache

app = Flask(__name__)
cache = Cache(app, config={"CACHE_TYPE": "SimpleCache"})

@app.route("/")
@cache.cached(timeout=50)
def index():
    return "This response is cached for 50 seconds"

Installation

Install the extension with the following command:

$ pip install Flask-Caching

or alternatively with uv:

$ uv add Flask-Caching

Flask-Caching 2.5.0 supports Python 3.11+.

Content

API

Additional Information