Why cache dependencies
Installing dependencies can consume significant CI time. Caching package-manager data can make repeated workflow runs faster when the cache key matches.
Cache keys must reflect dependency changes
A cache should be invalidated when the dependency lockfile or other relevant inputs change. Otherwise an old cache can produce confusing or incorrect builds.
Cache is an optimization
Workflows should remain correct when a cache is unavailable. Treat cached data as disposable acceleration rather than required application state.