refactor: extract generic CacheEntry to deduplicate cache read/write (#104)#116
Merged
refactor: extract generic CacheEntry to deduplicate cache read/write (#104)#116
Conversation
…#104) Also fix with_temp_cache to use catch_unwind so failing tests don't poison ENV_MUTEX and cascade to all other cache tests.
- read_cache doc: note that I/O errors propagate (not swallowed) - SAFETY comment: explain mutex poison recovery rationale - SAFETY comment: clarify the serialisation contract for XDG_CACHE_HOME
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Refactors the cache module to remove duplicated whole-file cache read/write logic by introducing a small Expiring trait plus generic read_cache<T> / write_cache<T> helpers, and aligns cache reads to treat JSON deserialization failures as cache misses instead of user-facing errors.
Changes:
- Added
Expiring+ generic whole-file cache read/write helpers and migrated team/workspace/cmdb_fields caches to use them. - Normalized keyed
project_metacache to treat corrupt JSON asOk(None)and documented why keyed caches aren’t genericized. - Improved cache test isolation by preventing mutex poisoning on panics and added new corrupt-cache tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/cache.rs |
Introduces generic cache helpers, updates cache read/write functions, hardens corrupt-cache behavior, and expands tests. |
docs/superpowers/specs/2026-04-02-cache-dedup-design.md |
Adds a design spec describing the refactor approach and behavior changes. |
docs/superpowers/plans/2026-04-02-cache-dedup.md |
Adds an implementation plan outlining incremental steps and validation commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…che (#104) Avoids swallowing permission errors and eliminates TOCTOU window between the exists check and the read.
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
Expiringtrait + genericread_cache<T>/write_cache<T>to deduplicate 3 whole-file cache pairs (teams, workspace, cmdb_fields)Ok(None)) — previously only 2 of 5 did thiswith_temp_cacheto prevent mutex poisoning on test panicsCloses #104
Test plan
cargo test)cargo clippy -- -D warnings)cargo fmt --all -- --check)