Set Cache-Control headers on the Flask response
Project description
Flask-CacheControl
Description:
A light-weight library to conveniently set Cache-Control headers on the response. Decorate view functions with cache_for, cache, or dont_cache decorators. Makes use of Flask response.cache_control.
This extension does not provide any caching of its own. Its sole purpose is to set Cache-Control and related HTTP headers on the response, so that clients, intermediary proxies or reverse proxies in your jurisdiction which evaluate Cache-Control headers, such as Varnish Cache, do the caching for you.
Example:
from flask.ext.cachecontrol import (
FlaskCacheControl,
cache,
cache_for,
dont_cache)
flask_cache_control = FlaskCacheControl()
flask_cache_control.init_app(app)
@app.route('/')
@cache_for(hours=3)
def index_view():
return render_template('index_template')
@app.route('/stats')
@cache(max_age=3600, public=True)
def stats_view():
return render_template('stats_template')
@app.route('/dashboard')
@dont_cache()
def dashboard_view():
return render_template('dashboard_template')
Breaking Changes:
v0.2.0
- By default, cache control headers are only applied to successful requests. (status code
2xx
) This behaviour can be customized by providingonly_if=
as a kw to all caching decorators. - Requires python 3.3 or higher
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for Flask_CacheControl-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b1aa9b70d03b674022768fc2ac99083d6e8e44bca4f5fcff299778e7c38b4b7 |
|
MD5 | 34f5ec6f82156c3ec1828f695c5b408d |
|
BLAKE2b-256 | d8777b13bfb4600fca7ca1e023daf67c68db49981e2a961723b3636cefa79cff |