API Reference
- class cache.async_cache.AsyncCache(maxsize=128, default_ttl=None, batch_window_ms=5, max_batch_size=100)[source]
Bases:
object- async get(key, loader=None, batch_loader=None, ttl=None)[source]
Get from cache, loader on miss, with thundering herd protection for concurrent misses on same key. Uses _pending_lock to avoid race conditions when multiple async tasks (e.g., HTTP requests) miss simultaneously. Only one loader executes; others await the future result. Batch mode for multi-key. LRU ops protected by RLock in lru.LRU (prevents eviction races in parallel re-runs/hits near maxsize).
- class cache.async_lru.AsyncLRU(maxsize=128, skip_args=0)[source]
Bases:
object- Parameters:
skip_args (int)
- class cache.async_ttl.AsyncTTL(time_to_live=60, maxsize=1024, skip_args=0)[source]
Bases:
object- Parameters:
skip_args (int)
- class cache.key.KEY(args, kwargs)[source]
Bases:
objectImmutable, hash/eq-stable key for cache (args + kwargs). Fixes prior bugs: - __eq__ was hash-only (violated contract: a==b but hashes differ possible; collisions). - Hash unstable (dict.items() order pre-3.7, str(vars) arbitrary, kwargs.pop mutated caller!). - Now: frozen tuples, recursive _to_hashable (sorted dicts, stable obj repr), no mutation. Guarantees hash(a)==hash(b) iff a==b; stable across runs/Python versions. Used via make_key in decorators/AsyncCache.