Skip to content

pico-caching v0.1.0

Choose a tag to compare

@dperezcabrera dperezcabrera released this 04 Jul 15:46

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 @component method — 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 by cache.max_entries.
  • Bring your own backend: implement the 4-method CacheBackend protocol as a @component and it replaces the built-in automatically — no registry, no config.
  • Repr-based default keys (explicit and debuggable); key=callable for custom keys.
  • Exceptions are never cached; cache.enabled: false bypasses 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: false bypasses, and LRU eviction order in the built-in backend.

Install

pip install pico-caching