Add Multiton.clear_cache with type and key filters - #11
Merged
Merged
Conversation
Evicts the entire cache (and expiry heap), or only entries whose cached instance matches a type, tuple of types or union via isinstance. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Add FrozenKey.factory, args and kwargs accessors and a where(key, instance) predicate to Multiton.clear_cache, so callers can evict entries by what created them (e.g. one dataset's tables) rather than only by instance type. clear_cache now returns the number of entries evicted. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The where predicate now receives only the cached instance, which is the supported way to decide what to evict. FrozenKey no longer exposes factory, args and kwargs reconstructed from its frozen tuple. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch was successfully deployed
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.
Adds a public way to evict cached Multiton instances, motivated by ratt-ru/xarray-ms#177 (part 2: no public, per-measurement-set way to evict cached tables).
Changes
Multiton.clear_cache(instance_type=None, *, where=None) -> intinstance_typematches withisinstance(a type, tuple of types or union, subclasses included).where(instance)matches on the cached instance itself, so callers can evict only instances tied to a particular resource, e.g. one dataset's table handles, while leaving other entries (such as an expensive derived structure) cached.Like
release(),clear_cachedoesn't wait for constructions already in progress.Intended use in xarray-ms
This is independent of part 1 of that issue (memory retained per
MSv2Structurebuild). That was a reference leak in arcae'smerge_np_partitions, fixed in ska-sa/arcae#244.release(ms)still avoids an unnecessary structure rebuild when only the table handles need reopening.Tests
New tests cover full and filtered clears, subclass/tuple/union matching,
wherewith AND semantics, the return count, stale heap entries after a clear, and a per-dataset eviction that mirrors xarray-ms's table/subtable/structure layout.🤖 Generated with Claude Code