Search code examples
node.jscachingcircleci

Circle CI cache mismatch


I'm wondering why Circle Ci saves the cache in a different key than it restores from despite the config.yml that has the same keys.

 steps:
  - checkout
  - restore_cache:
      keys:
        - node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
  - run: npm install
  - save_cache:
      paths:
        - ~/usr/local/lib/node_modules
      key: node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
  - run: npm run linter

enter image description here

Is there something I should change in the configuration?


Solution

  • Somehow this got fixed. I've done some changes. First I've changed the config.yml so that restore & save cache come after each other.

    steps:
      - checkout
      - restore_cache:
          keys:
            - node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - save_cache:
          paths:
            - ~/usr/local/lib/node_modules
          key: node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run: npm ci
    

    Then I've switched it back.

    steps:
      - checkout
      - restore_cache:
          keys:
            - node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run: npm ci
      - save_cache:
          paths:
            - ~/usr/local/lib/node_modules
          key: node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
    

    This might have reset the keys somehow.

    enter image description here

    I've also replaced npm install with npm ci.