feat(hashing): add read_only and min_cache_size_bytes write guards to hash cachers#222
Merged
eywalker merged 12 commits intoJul 10, 2026
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…oryHashCacher Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eHashCacher Mirrors the guards already present in InMemoryHashCacher: put() is a silent no-op when read_only=True or when key.size is below the min_cache_size_bytes threshold. Also adds __repr__ and updates the class docstring with the new keyword-only args.
…ile_hash_caching Add read_only and min_cache_size_bytes keyword-only parameters to enable_file_hash_caching() and pass them through to SqliteHashCacher. Add two pass-through tests to TestEnableFileHashCaching to verify the parameters are correctly forwarded to the underlying cacher.
Add a new "Controlling when the cache is written" section covering read-only mode and the minimum file size threshold, and update the "Files are small" bullet to reference min_cache_size_bytes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
eywalker
approved these changes
Jul 10, 2026
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
read_only: bool = Falseandmin_cache_size_bytes: int | None = Nonekeyword-only arguments to bothInMemoryHashCacherandSqliteHashCacherread_only=True, allput()calls are silent no-ops (reads still work normally — useful for consuming a pre-populated cache without polluting it)min_cache_size_bytesis set to a positive integer, files smaller than the threshold are not inserted into the cache (hash is still computed and returned to the caller)read_only=Truealways wins;min_cache_size_bytesapplies only when writablemin_cache_size_bytesraisesValueErrorat construction timeenable_file_hash_caching(read_only=..., min_cache_size_bytes=...)for the public APIdocs/concepts/file-hash-caching.mdwith a new "Controlling when the cache is written" sectionTest plan
tests/test_hashing/test_hash_cacher_write_guards.pypasstests/test_hashing/test_hash_cachers.pypassuv run pytest tests/test_hashing/ -vInMemoryHashCacherandSqliteHashCacherread-only mode:put()is a no-op,get()still worksCachedFileHasherintegration: hash is computed and returned regardless of cacher write guardsValueErrorraised for negativemin_cache_size_byteson constructionenable_file_hash_caching(read_only=True, min_cache_size_bytes=1024)correctly wires both args intoSqliteHashCacherFixes ITL-519
🤖 Generated with Claude Code