pico-caching v0.1.0
pico-caching v0.1.0
First public release. Declarative method caching (@cacheable) over pico-ioc interception with pluggable backends, auto-discovered by pico-boot. Zero-config. No prior versions; no migration required.
Highlights
@cacheable(ttl_seconds, key=...)on any@componentmethod — sync or async; the awaited result is cached, never the coroutine.- Built-in backend: thread-safe in-memory LRU with per-entry TTL (
time.monotonic), bounded bycache.max_entries. - Bring your own backend: implement the 4-method
CacheBackendprotocol as a@componentand it replaces the built-in automatically — no registry, no config. - Repr-based default keys (explicit and debuggable);
key=callablefor custom keys. - Exceptions are never cached;
cache.enabled: falsebypasses everything.
Deliberately not in v0.1.0
@cache_evict and a Redis backend — planned once real usage asks for them. Invalidate today by injecting the backend (delete/clear).
Example
from pico_ioc import component
from pico_caching import cacheable
@component
class UserRepo:
@cacheable(ttl_seconds=60)
async def find(self, user_id: int): ...Compatibility
- Python 3.11+ · pico-ioc >= 2.2.0
Tests
- 5 tests. Pinned behaviors: hit/miss per argument set, TTL expiry, async caches the awaited result (single execution across awaits),
enabled: falsebypasses, and LRU eviction order in the built-in backend.
Install
pip install pico-caching