0%
Dependency Caching and Artifacts Between Jobs

Cache and Artifacts

Two distinct mechanisms, often confused, with very different effects.

10-15 min

On a mid-sized JavaScript project, npm ci takes between sixty and one hundred twenty seconds. Multiply that by the number of jobs in your workflow, by the number of commits per day, by the number of people on the team: it's the biggest time sink in a continuous integration pipeline, and it verifies nothing. On every run, it re-downloads packages that haven't changed in three weeks.

Caches and artifacts address two needs that are constantly confused. The cache is for avoiding work whose result can be rebuilt: downloaded dependencies, intermediate build objects. It is disposable by nature: if the cache disappears, the pipeline still works, just more slowly. The artifact is for carrying a result you want to keep or pass along: a compiled executable, a test report, a screenshot from a failed test. Using an artifact as a cache leads to slow runs and saturated storage; using a cache to carry a binary leads to intermittent failures, on the day the cache is missing.

Caching Dependencies

The simplest approach is often the best: the setup-* actions can manage the cache themselves.

      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: npm

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!