Automation · GitHub Actions
Caching
Cheat sheet · https://pcornel.dk/topic.php?topic=5530
Answer
Caching in GitHub Actions stores dependencies like npm, pip or Maven files between runs with actions/cache or setup-* cache options, keyed by lock-file hashes to speed up builds.
Remember
- Key caches on hashes of lock files.
- setup-node, setup-python and others have built-in caching.
- A stale or poisoned cache can break builds.
First checks
- actions/cache key with hashFiles(lock files) — correct key
gh cache list— caches- Cache scope per branch — poisoning risk
Verify in this order
key → restore → build → save
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
GitHub Actions → Caching · operational reference
| Layer | GitHub Actions → Caching operational reference |
|---|---|
| Runtime/ownership | GitHub Actions dependency caching · the GitHub Actions cache service together with the workflow job and cache action/setup action that computes lookup keys |
| Persistent intent | workflow YAML defining cache paths, exact key, restore keys and the trust context allowed to read or write caches |
| Verification | Run the job once with a guaranteed cache miss and once with the intended key; inspect cache-hit metadata and verify the build/test result is identical apart from performance. |
| Expected interpretation | The correct cache scope/key is selected, untrusted contexts cannot gain inappropriate write capability, misses rebuild successfully, and restored data does not alter the verified build result. |
| Recovery boundary | disable or version-bump the suspect key, reproduce on a clean cache miss, repair key/trust scoping, then compare dependency lock data and build/test output |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5530