Skip to content

feat(hashing): add read_only and min_cache_size_bytes write guards to hash cachers#222

Merged
eywalker merged 12 commits into
mainfrom
eywalker/itl-519-filehasher-cache-add-read-only-mode-minimum-file-size
Jul 10, 2026
Merged

feat(hashing): add read_only and min_cache_size_bytes write guards to hash cachers#222
eywalker merged 12 commits into
mainfrom
eywalker/itl-519-filehasher-cache-add-read-only-mode-minimum-file-size

Conversation

@kurodo3

@kurodo3 kurodo3 Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds read_only: bool = False and min_cache_size_bytes: int | None = None keyword-only arguments to both InMemoryHashCacher and SqliteHashCacher
  • When read_only=True, all put() calls are silent no-ops (reads still work normally — useful for consuming a pre-populated cache without polluting it)
  • When min_cache_size_bytes is 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)
  • Both guards compose: read_only=True always wins; min_cache_size_bytes applies only when writable
  • Negative min_cache_size_bytes raises ValueError at construction time
  • Exposes both knobs through enable_file_hash_caching(read_only=..., min_cache_size_bytes=...) for the public API
  • Updates docs/concepts/file-hash-caching.md with a new "Controlling when the cache is written" section

Test plan

  • All 41 new tests in tests/test_hashing/test_hash_cacher_write_guards.py pass
  • 2 new pass-through tests in tests/test_hashing/test_hash_cachers.py pass
  • Total test suite passes: uv run pytest tests/test_hashing/ -v
  • InMemoryHashCacher and SqliteHashCacher read-only mode: put() is a no-op, get() still works
  • Threshold mode: files below threshold are not stored, files at/above threshold are stored
  • CachedFileHasher integration: hash is computed and returned regardless of cacher write guards
  • ValueError raised for negative min_cache_size_bytes on construction
  • enable_file_hash_caching(read_only=True, min_cache_size_bytes=1024) correctly wires both args into SqliteHashCacher

Fixes ITL-519

🤖 Generated with Claude Code

kurodo3 Bot and others added 12 commits July 10, 2026 02:31
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

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@eywalker eywalker merged commit fd9211a into main Jul 10, 2026
11 checks passed
@eywalker eywalker deleted the eywalker/itl-519-filehasher-cache-add-read-only-mode-minimum-file-size branch July 10, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant