Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is a cache miss

Tags:

azure-devops

I'm trying to cache the cypress installation in my build pipeline.

I have this task setup:

- task: Cache@2
  inputs:
    key: 'cypress | $(Agent.OS) | package-lock.json'
    path: 'C:\npm\prefix\node_modules\cypress'

I've run the build pipeline multiple times but I'm always getting the same error:

There is a cache miss

enter image description here

This is the previous build:

enter image description here

As you can see it's the same fingerprint, so why is the caching not working?

like image 760
Peter Boomsma Avatar asked Oct 24 '25 19:10

Peter Boomsma


2 Answers

One more thing - In order that cache task works as expected all task must succeed.

enter image description here

like image 167
Kqly Avatar answered Oct 27 '25 19:10

Kqly


Check the "cache post-job task" results and see if the keys are different.

In my case I had to use npm install --no-save so that the package-lock.json file wasn't regenerated during the pipeline. This ensured the "cache post-job task" was using the same cache key when caching node_modules.

edit

Here is an exported example of what we currently use in our pipeline to cache npm modules.

(You must make sure that your package-lock.json is checked in to your code repository)

steps:
- task: Cache@2
  displayName: 'Npm Install Cache'
  inputs:
    key: '"npm" | "$(Agent.OS)" | my-project/package-lock.json'
    path: 'my-project/node_modules'
    cacheHitVar: NpmInstallCached

- task: Npm@1
  displayName: 'Npm Install'
  inputs:
    command: custom
    workingDir: my-project/
    verbose: false
    customCommand: 'install --no-save'
  condition: ne(variables['NpmInstallCached'], 'true')
like image 38
Peter Avatar answered Oct 27 '25 19:10

Peter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!