package-lock.json (or yarn.lock) is updated. This ensures fast builds when dependencies are unchanged, and safe cache refreshes when they are not.

package-lock.json). When that file changes, the plugin computes a new hash and decides whether an existing cache is still valid. Below is the Jenkins pipeline snippet used to cache node_modules and to make package-lock.json the cache-validity file.
package.json and package-lock.json. When you commit and push these changes the pipeline triggers, and the Job Cacher plugin computes a hash of package-lock.json and compares it with the hash associated with the stored cache archive.
Representative pipeline logs for the two outcomes:
- Cache is up-to-date and is restored:
package-lock.jsonchanged — cache is outdated and is recreated:
- The plugin computes a hash of the configured cache-validity file(s) (in this example:
package-lock.json) in the current workspace. - It compares that hash with the hash associated with the existing cache for this job.
- If the hashes match, the plugin restores the cache and the build step finishes quickly (for example:
npm installreports “up to date”). - If the hashes differ, the plugin treats the cache as outdated, skips restoration, runs the install to produce up-to-date
node_modules, then creates a new cache using the new hash.
- If the hashes match, the plugin restores the cache and the build step finishes quickly (for example:
- Subsequent builds with the same
package-lock.jsoncontent will restore the newly created cache until the lockfile changes again.
Use
cacheValidityDecidingFile (for example, package-lock.json or yarn.lock) so the Job Cacher invalidates dependency caches whenever the lockfile changes. This maintains build speed for unchanged dependencies while preventing stale or incompatible modules from being reused.- Job Cacher plugin (Jenkins) — check the plugin documentation in your Jenkins instance or the plugin site for configuration details.
- Jenkins pipeline documentation: https://www.jenkins.io/doc/book/pipeline/
- npm lockfile formats and behavior: https://docs.npmjs.com/cli/v9/configuring-npm/package-lock-json