Server-side HTTP caching for ASGI applications, inspired by Django's cache framework
Project description
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
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file starlette_caches-0.4.1.tar.gz.
File metadata
- Download URL: starlette_caches-0.4.1.tar.gz
- Upload date:
- Size: 96.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
668370885d5efe71e4f55f60c91035516f64d003fb5a04abbb0910e5e052416e
|
|
| MD5 |
58faaf85933e3e29a8073d5e3ad2cdae
|
|
| BLAKE2b-256 |
e96ec91ed981927e79d479c5c1aef9b68bbf9fa838ac312f2bcf5b8c3b15abd1
|
Provenance
The following attestation bundles were made for starlette_caches-0.4.1.tar.gz:
Publisher:
release.yml on mattmess1221/starlette-caches
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
starlette_caches-0.4.1.tar.gz -
Subject digest:
668370885d5efe71e4f55f60c91035516f64d003fb5a04abbb0910e5e052416e - Sigstore transparency entry: 179798828
- Sigstore integration time:
-
Permalink:
mattmess1221/starlette-caches@fa4d6080d3be7d15aced7d904dea89e4b01fe711 -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/mattmess1221
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fa4d6080d3be7d15aced7d904dea89e4b01fe711 -
Trigger Event:
release
-
Statement type:
File details
Details for the file starlette_caches-0.4.1-py3-none-any.whl.
File metadata
- Download URL: starlette_caches-0.4.1-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1909e80ded720cf0e37a084b3b2a8da0f7c26c24c2d82c9079b32fc038e34cf
|
|
| MD5 |
570f4cde2f556b5482c2cc97cc24c81c
|
|
| BLAKE2b-256 |
5010f2f0a3664f0e9a2014ab9940eb39124f7785b83ce634e6cf8bc2a0e7502d
|
Provenance
The following attestation bundles were made for starlette_caches-0.4.1-py3-none-any.whl:
Publisher:
release.yml on mattmess1221/starlette-caches
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
starlette_caches-0.4.1-py3-none-any.whl -
Subject digest:
c1909e80ded720cf0e37a084b3b2a8da0f7c26c24c2d82c9079b32fc038e34cf - Sigstore transparency entry: 179798833
- Sigstore integration time:
-
Permalink:
mattmess1221/starlette-caches@fa4d6080d3be7d15aced7d904dea89e4b01fe711 -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/mattmess1221
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fa4d6080d3be7d15aced7d904dea89e4b01fe711 -
Trigger Event:
release
-
Statement type: