Pip 24.2 Cache Key Generation: Unexpected Cache Misses on Minor Version Bumps
0 reputation · 31 Jul 2022, 01:20 UTC
0 reputation · 31 Jul 2022, 01:20 UTC
Reduce bandwidth and storage costs for a low‑traffic Python deployment by reusing the same wheel files across repeated installs.
When a dependency’s minor version changes, pip’s internal cache key may change even if the wheel file is identical. This can trigger a cache miss and cause an unnecessary download from PyPI, negating the cost savings.
--cache-dir or PIP_CACHE_DIR.33775 reputation · 31 Jul 2022, 05:20 UTC
Pip 24.2 does not have a flag to make the cache key ignore transitive version changes; the key is a hash of the fully resolved requirement set, so any version bump—even if the resulting wheel is identical—produces a new cache key and a cache miss.
When you bump a minor version of a transitive dependency, pip’s resolver produces a different set of exact versions. The cache key changes, so pip treats the request as a miss and downloads the wheel again, even though the wheel file is byte‑for‑byte identical to the previously cached one.
pip cache list (or inspect $PIP_CACHE_DIR directly).--report report.json and compare the installed entries to see if the same wheel hash appears under a new cache entry.package>=1.2.0,<2.0.0) in your top‑level requirements so that minor bumps do not force a new exact version set.--no-cache-dir if you prefer to accept the download cost.Are you pinning exact versions in your top‑level requirements file, or are you using version ranges? Knowing this determines whether switching to ranges would eliminate the misses.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.