starlette-caches
starlette-caches provides middleware and utilities for adding server-side HTTP caching to ASGI applications. It is powered by aiocache, and inspired by Django's cache framework.
Documentation is available at: https://mattmess1221.github.io/starlette-caches/
Note: this project is in an "alpha" status. Several features still need to be implemented, and you should expect breaking API changes across minor versions.
Features
- Compatibility with any ASGI application (e.g. Starlette, FastAPI, Quart, etc.).
- Support for application-wide or per-endpoint caching.
- Ability to fine-tune the cache behavior (TTL, cache control) down to the endpoint level.
- Clean and explicit API enabled by a loose coupling with
aiocache. - Fully type annotated.
- 100% test coverage.
Installation
pip install "starlette-caches"
To install with redis or memcached support, use:
pip install "starlette-caches[redis,memcached]"
Quickstart
from aiocache import Cache
from starlette_caches.middleware import CacheMiddleware
cache = Cache(ttl=2 * 60)
async def app(scope, receive, send):
assert scope["type"] == "http"
headers = [(b"content-type", "text/plain")]
await send({"type": "http.response.start", "status": 200, "headers": headers})
await send({"type": "http.response.body", "body": b"Hello, world!"})
app = CacheMiddleware(app, cache=cache)
This example:
- Sets up an in-memory cache (see the aiocache docs for specifics).
- Sets up an application (in this case, a raw-ASGI 'Hello, world!' app).
- Applies caching on the entire application.
To learn more, head to the documentation.
Credits
Due credit goes to the Django developers and maintainers, as a lot of the API and implementation was directly inspired by the Django cache framework.
License
MIT
Metadata
Release files for starlette-caches 0.4.1
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 | |
|---|---|---|---|---|
| starlette_caches-0.4.1.tar.gz | 96.4 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| starlette_caches-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 113.0 kB
Release files / starlette_caches-0.4.1.tar.gz
| Download URL | starlette_caches-0.4.1.tar.gz |
|---|---|
| Size | 96.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
668370885d5efe71e4f55f60c91035516f64d003fb5a04abbb0910e5e052416e
|
|
BLAKE2b-256 checksum How to use checksums |
e96ec91ed981927e79d479c5c1aef9b68bbf9fa838ac312f2bcf5b8c3b15abd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 10, 2025.
Transparency logRelease files / starlette_caches-0.4.1-py3-none-any.whl
| Download URL | starlette_caches-0.4.1-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1909e80ded720cf0e37a084b3b2a8da0f7c26c24c2d82c9079b32fc038e34cf
|
|
BLAKE2b-256 checksum How to use checksums |
5010f2f0a3664f0e9a2014ab9940eb39124f7785b83ce634e6cf8bc2a0e7502d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 10, 2025.
Transparency logSecurity for starlette-caches 0.4.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for starlette_caches-0.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 10, 2025.
Transparency logA 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.