GitLab CI Cache Not Being Restored Between Jobs
Why your `node_modules` or `.cache/` keeps re-downloading and how to make the cache actually hit.
Problem
Every job re-installs dependencies. Logs say `Cache not found` even though the previous job ran `cache:`.
Root cause
- Different runners with separate local cache directories.
- Cache key changes every run (e.g. uses $CI_JOB_ID).
- Distributed cache (S3) is not configured.
- Job runs in a different stage with `policy: pull-push` mismatch.
Solution
Use a stable, file-based cache key
cache:
key:
files: [package-lock.json]
paths: [node_modules/]
policy: pull-pushUse distributed cache when you have multiple runners
# /etc/gitlab-runner/config.toml
[runners.cache]
Type = "s3"
Shared = true
[runners.cache.s3]
ServerAddress = "s3.amazonaws.com"
BucketName = "gitlab-runner-cache"Frequently asked questions
Related fixes
GitLab CI/CD
5 minFix GitLab CI Job Stuck on "pending"
Pipeline waits forever for a runner. The fix is almost always tags, scope, or capacity.
#runners#tags#pipelines
GitLab CI/CD
3 minFix GitLab CI "jobs config should contain at least one visible job"
Lint errors on .gitlab-ci.yml and how to debug invalid pipeline syntax fast.
#yaml#validation
Weekly digest
One DevOps fix in your inbox each week
Short, practical, no fluff. Real errors, real fixes — straight from production postmortems.