fix(cache): CacheManager protocol, async-only guard, clear key errors, InMemoryCache max_size LRU (v26.06.15)#41
Merged
Merged
Conversation
…ear key errors, InMemoryCache max_size LRU + bump v26.06.15 Surfaced by an edge-case audit while validating implement-cache-strategy (skill clean: cache hits skip the source, evict invalidates). Framework fixes: - CacheManager: add the missing CacheAdapter methods (exists/put_if_absent/ evict_by_prefix/start/stop) so isinstance(mgr, CacheAdapter) holds and it works as a decorator backend (was AttributeError on .exists for null-cached hits). - decorators: reject a sync target at decoration time with a clear TypeError (was a cryptic await TypeError at call time); raise a clear ValueError naming the unknown parameter for a bad key template (was a bare KeyError). - InMemoryCache: optional max_size with LRU eviction (wired from pyfly.cache.max-size); default stays unbounded. The advertised max_size stat is now honest. Documented two by-design properties: key namespace = backend instance + key template (so cross-method evict works), and the lossy Redis JSON round-trip (model -> dict on hit). Tests: tests/cache/test_cache_hardening.py (7). Gates: mypy --strict (607), ruff + format, full suite 3681 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An edge-case audit while validating the
implement-cache-strategyskill (which validated clean — cache hits provably skip the source via an observable counter, and evict invalidates) surfaced real framework bugs in untested corners.Fixed
CacheManagerdidn't satisfy its declaredCacheAdapterprotocol. It implemented onlyget/put/evict/clear, soisinstance(mgr, CacheAdapter)wasFalseand using one as a@cacheablebackend raisedAttributeError: 'CacheManager' object has no attribute 'exists'on the first null-cached hit. Addedexists/put_if_absent/evict_by_prefix/start/stop(mirrored to primary + fallback).awaitan async backend, so a sync target failed with a crypticawaitTypeErrorat call time. They now raise a clearTypeErrorat decoration time.KeyErrorat call time; now a clearValueErrornaming the unknown parameter.Added
InMemoryCache(max_size=...)with LRU eviction, wired frompyfly.cache.max-size. The adapter was unbounded (themax_sizestat was alwaysNone— advertised but unimplemented); default stays unbounded.Documented (by-design, not bugs)
@cache_evictinvalidate a@cacheableentry; qualname-namespacing would break that pattern).dicton a Redis hit, unlike the in-memory adapter).Tests / Gates
tests/cache/test_cache_hardening.py(7): manager protocol + decorator-backend null-caching, sync-rejection, bad-key error, LRU eviction + unbounded default.mypy --strict(607) ✓ ·ruff+ruff format✓ · full suite 3681 passed, 1 skipped.Bumps
v26.06.14 → v26.06.15, CHANGELOG,uv.locksynced.