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.
By default, Cache-Control headers are only appended in case of a
successful response (status code 2xx). This behaviour can be controlled
with the only_if argument to cache_for and cache decorators. Included
options are Always, ResponseIsSuccessful, ResponseIsSuccessfulOrRedirect. Custom behaviour can be implemented by subclassing OnlyIfEvaluatorBase.
If the vary keyword argument is given to cache_for or cache
decorators, the Vary HTTP header is returned with the response.
Vary headers are appended independent of response status code.
Example
from flask import Flask, render_template
from flask_cachecontrol import (
cache,
cache_for,
dont_cache,
Always,
ResponseIsSuccessfulOrRedirect)
app = Flask(__name__)
@app.route('/')
@cache_for(hours=3)
def index_view():
return render_template('index_template')
@app.route('/users')
@cache_for(minutes=5, only_if=ResponseIsSuccessfulOrRedirect)
def users_view():
return render_template('user_template')
@app.route('/stats')
@cache(max_age=3600, public=True, only_if=Always, vary=['User-Agent', 'Referer'])
def stats_view():
return render_template('stats_template')
@app.route('/dashboard')
@dont_cache()
def dashboard_view():
return render_template('dashboard_template')
Changelog
0.3.0
- Add
only_ifevaluator for successful or redirect (2xx, 3xx) responses (#7) - Support Vary-headers (#6)
- Improve instantiation of callbacks and registry provider
- BREAKING: Simplify instantiation and hooking into flask response handling (#8)
- No more need to instantiate
FlaskCacheControlfor Flask app.
- No more need to instantiate
- BREAKING: Drop support for
only_if=None- Use more explicit
only_if=Alwaysinstead
- Use more explicit
- BREAKING: Restructure modules
- Direct imports from modules inside the package need to be adapted.
- Improve test structuring
- Fix flask instantiation and import in example
v0.2.1
- Fix import statement in example
v0.2.0
- Add tests
- BREAKING: 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. - BREAKING: Requires python 3.3 or higher
Metadata
Release files for Flask-CacheControl 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-CacheControl-0.3.0.tar.gz | 5.6 kB | Without provenance | Details for Flask-CacheControl-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_CacheControl-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for Flask_CacheControl-0.3.0-py3-none-any.whl |
Total release size: 14.9 kB
Release files / Flask-CacheControl-0.3.0.tar.gz
| Download URL | Flask-CacheControl-0.3.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39d10ce9dac835f926035b71eec5c8711b2625ecb27dd9b43f09a16ee5235e4e
|
|
BLAKE2b-256 checksum How to use checksums |
82e6263fadac78f426428bc9705694069955a3c27b8f1d5b318ed23641d68d0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Release files / Flask_CacheControl-0.3.0-py3-none-any.whl
| Download URL | Flask_CacheControl-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d75f56d8f9288d13758da69e7af4c4d9adcd87e7e5db5f57124c6f326e7c89c
|
|
BLAKE2b-256 checksum How to use checksums |
c17217ea30f6c30d8181601765942cc0869151d2731c0b07a02aca01bccb520a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Security for Flask-CacheControl 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.