Server-side HTTP caching for ASGI applications, inspired by Django's cache framework
asgi-caches
provides middleware and utilities for adding server-side HTTP caching to ASGI applications. It is powered by async-caches
, and inspired by Django’s cache framework.
Documentation is available at: https://florimondmanca.github.io/asgi-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.
async-caches
.pip install "asgi-caches==0.*"
from asgi_caches.middleware import CacheMiddleware
cache = Cache("locmem://null")
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:
To learn more, head to the documentation.
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.
MIT