Getting Started¶
Install¶
Basic usage¶
@cacheable # default TTL (caching.default_ttl_seconds)
def find(self, user_id): ...
@cacheable(ttl_seconds=5) # per-method TTL
def hot(self): ...
@cacheable(key=lambda q: f"s:{q}") # custom key from the call args
def search(self, q): ...
Sync and async both work; for async methods the awaited result is cached, never the coroutine. The default key includes class, method and the repr of every argument — same args, same entry.
Settings¶
Custom backend¶
Implement the protocol as a @component — it replaces the built-in automatically: