Dedicated cache directory per ruff version#8333
Conversation
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
| pub(crate) fn open(package_root: PathBuf, settings: &Settings) -> Self { | ||
| debug_assert!(package_root.is_absolute(), "package root not canonicalized"); | ||
|
|
||
| let mut buf = itoa::Buffer::new(); |
There was a problem hiding this comment.
Using itoa to write a single number felt overkill.
charliermarsh
left a comment
There was a problem hiding this comment.
Will we still automatically clear old entries with this approach?
PR Check ResultsEcosystem✅ ecosystem check detected no linter changes. ✅ ecosystem check detected no format changes. |
We continue to automatically clear old file entries, the same as the old version. What the version doesn't (nor did the baseline) is to clean up caches of old versions (except if you run |
|
Oh interesting, so even the existing cache will never remove files from old versions? |
Not as far as I know. The only cleanup code that I see is the removal of stale entries: ruff/crates/ruff_cli/src/cache.rs Lines 192 to 197 in 6199590 But there's no operation that iterates over all files and cleans unused entries, other than the |

Summary
This PR changes our cache to use a dedicated cache directory per ruff version.
.ruff_cache/content.ruff_cache/0.1.3The motivation is that I want to rule out that hash collisions between cache keys causing ruff to load a cache created by another version.
Loading incompatible caches might be the root cause for #8147 (although unlikely, because users mention that they didn't upgrade ruff)
Other hash collissions are less problematic, because the Cache checks if the loaded file is for the same package, and otherwise clears the cache for that package.
Open questions
I'm unsure if this is considered a breaking change or not. It does change observable behavior of Ruff but we never included it in our public API.
Test Plan
Verified that the cache is still used by comparing performance before/after