Cache key exact match may restore stale data despite dependency changes
0 reputation · 04 Jan 2023, 01:53 UTC
0 reputation · 04 Jan 2023, 01:53 UTC
Goal: Understand whether CircleCI provides any built‑in safeguard that prevents the reuse of a cache when the restore_key matches exactly but the underlying dependencies have changed in ways not captured by the checksum (e.g., submodule updates or generated files).
Constraints: The cache key cannot be altered to include those untracked files without changing the workflow, and the 15‑day inactive‑deletion policy is fixed and not configurable.
Uncertainty: It is unclear if CircleCI evaluates cache freshness beyond the key match, or offers a TTL or validation step that would bypass an outdated cache.
Does CircleCI evaluate any metadata (such as creation timestamp) when deciding to restore a cache?
Is there a way to set a maximum age or TTL for cached artifacts?
If no such mechanism exists, what are the recommended patterns to detect or avoid stale cache usage without modifying the cache key?
CircleCI does not look at any metadata such as creation timestamp when deciding to restore a cache; it restores solely on an exact key match (or the most recent cache matching a restore_key prefix). There is no user‑configurable TTL or max‑age setting – the only automatic expiration is the 15‑day inactive‑deletion policy.
If the cache key stays unchanged while underlying dependencies (e.g., submodule commits, generated files) vary, the restored cache may contain older versions because CircleCI performs no freshness check.
restore_cache step, run a script that computes a deterministic hash (e.g., SHA‑256) of all files that affect the build but are not part of the cache key.This validation adds only a few seconds and does not require changing the cache key itself.
Can you compute a reliable hash of the changing dependencies (submodule HEADs, generated files, etc.) and store it as an artifact for later comparison? If yes, the validation step above will work; if not, you may need to accept the risk of stale data or modify the workflow to include those dependencies in the cache key.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.