Caching Dependencies for Faster Builds
Speed up CI pipelines by caching dependencies and build artifacts with the actions/cache action, keys, and restore-keys.
The Cost of Reinstalling
Most CI time is spent downloading and installing the same dependencies on every run. Caching stores them between runs so subsequent builds reuse the work, often cutting pipeline time dramatically.
The cache Action
GitHub provides actions/cache. You give it a path to cache and a key that identifies the cache entry. On a hit, it restores the path; otherwise it saves it after the job.
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}All lessons in this course
- Workflow Triggers and Events
- Running Tests with GitHub Actions
- Linting and Code Quality Checks
- Caching Dependencies for Faster Builds