Chirp caching framework.
Three levels of caching:
- Per-view:
@cache_view(ttl=300) - Site-wide:
CacheMiddleware(opt-in) - Template fragment:
{% cache "key" ttl %}...{% endcache %}
Usage::
from chirp.cache import get_cache, cache_view
@app.route("/products")
@cache_view(ttl=300)
async def products():
return await db.fetch(Product, "SELECT * FROM products")
# Low-level
cache = get_cache()
await cache.set("key", b"value", ttl=600)
cache
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
function
get_cache
function
set_cache
function
create_backend
function
cache_view
Return the current cache backend. None if no cache configured.
Set the cache backend for the current context.
Create a cache backend by name.
Decorator to cache a view's response.
Usage::
@app.route("/products")
@cache_view(ttl=300)
async def products():
...
get_cache
function
def get_cache() -> CacheBackend | None
Return the current cache backend. None if no cache configured.
No parameters.
set_cache
function
def set_cache(backend: CacheBackend) -> None
Set the cache backend for the current context.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
backend
|
CacheBackend
|
— |
create_backend
function
def create_backend(name: str, **kwargs: Any) -> CacheBackend
Create a cache backend by name.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name
|
str
|
— | |
**kwargs
|
Any
|
— |
cache_view
function
def cache_view(ttl: int = 300, key_func: Callable[..., str] | None = None) -> Callable[[Callable[..., Any]], Callable[..., Any]]
Decorator to cache a view's response.
Usage::
@app.route("/products")
@cache_view(ttl=300)
async def products():
...
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
ttl
|
int
|
300
|
|
key_func
|
Callable[..., str] | None
|
None
|
View source · /home/runner/work/chirp/chirp/site/../src/chirp/cache/__init__.py:1