Strange (buggy?) caching behaviour

keys
nodejs
cache
2.0

#1

A branch of my nodejs project has been failing on cache retrieval issues for a while https://circleci.com/gh/wheresrhys/workflows/fetch-mock/tree/rhys%2Fbabel-polyfill

Initially I was building my cache key from package.json, but on reading how caches are harder to bust in circleci 2.0, I’ve now changed to committing package-lock.json and using that as the cache key. But I still get failures, and pretty weird ones:
https://circleci.com/workflow-run/9fb34ac0-c2c1-4ee2-8239-033d2479e1dc

The cache key generated when saving to cache is dependency-cache-atq4gqwOq2wnMOKvehgYFGyAyNaKr7DuHDD_H0BM5YY= https://circleci.com/gh/wheresrhys/fetch-mock/344

But the cache key generated when retrieving the cache is dependency-cache-vQdJyD32GUffAiOk8gJYu5zD9CwWOJRQT0QF0jbqK5I=. However, one job succeeds using this key (which shouldn’t correspond to any existing caches) https://circleci.com/gh/wheresrhys/fetch-mock/345, and all the other jobs fail.

Can anyone explain this behaviour?

github branch: https://github.com/wheresrhys/fetch-mock/pull/260/files


#2

Solved it. For some versions of npm there’s a bug/feature that means npm install will override the committed package-lock.json, hence its checksum is no longer a reliable key to use for naming the cache.

I solved this by using npm install --no-package-lock in CI only


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.