Why cache the package manager's download cache rather than `node_modules`?
AdvancedConceptCaching, Artifacts, Runners & ARC
Answer
npm ci deletes node_modules before installing, so a cached node_modules is wasted; and node_modules contains platform-specific native builds that break across OS or Node versions. Caching ~/.npm keeps downloads local while npm ci still gives a clean, lockfile-exact install. The exception is very large monorepos where install time itself dominates; then cache node_modules keyed on OS, Node version and lockfile hash, and skip npm ci on an exact hit.
More on Caching, Artifacts, Runners & ARC
How does `actions/cache` match keys and restore keys?IntermediateWhich caches can a branch restore from?AdvancedWhat are the cache size limits and eviction rules?BeginnerWhen should you use setup-* built-in caching instead of `actions/cache`?BeginnerHow do `actions/cache/restore` and `actions/cache/save` help?AdvancedHow do you cache Docker layers in GitHub Actions?Intermediate