Cache is the single biggest CI speedup
The first time you install dependencies, it takes minutes. The second time, with a warm cache, it takes seconds. actions/cache is the generic primitive; setup-* actions have built-in cache shortcuts.
Two ways to cache
1) Built-in cache (preferred)
actions/setup-python@v5withcache: pip.actions/setup-node@v4withcache: npm/pnpm/yarn.astral-sh/setup-uv@v3withenable-cache: true.actions/setup-go@v5caches the Go module cache by default.
2) Generic actions/cache
path:— what to cache.key:— primary key. Usually${{ runner.os }}-deps-${{ hashFiles('**/lockfile') }}.restore-keys:— fallback prefixes if exact key missing.
Cache pitfalls
- Caches are scoped per branch. main's cache is also visible from any branch — but feature branch caches are not visible from main.
- 10 GB total cache size per repo. Old caches are evicted LRU.
- Caching build output (
dist/,.next/) saves time but introduces correctness risk. Always validate the build still works on a cold cache occasionally.