title: Caching node_modules in Azure Pipelines takes longer than installing them
body: <p>I am running a self-hosted agent (Windows Server) and I am trying to reduce my pipeline build time by caching my node_modules. However, restoring the node_modules cache takes just as long as installing the packages from scratch. Also, looking at the log it gives me the impression that it is downloading/uploading the cache externally, rather than keeping the cache on the VM. If this is true, then my caching of the node_modules would result in transferring ~1GB of data on every build.</p>
  <p>What am I doing wrong?</p>
  <p>My goal is to simply maintain/keep the node_modules between builds on my self-hosted agent for the following reasons:</p>
  <ol>
  <li>To prevent installing the node_modules everytime</li>
  <li>To keep the node_modules/.cache folder for <a href="https://blog.nrwl.io/computation-caching-out-of-the-box-revamped-docs-community-plugins-and-more-in-nx-9-2-e97801116e02" rel="nofollow noreferrer">computational caching</a> purposes</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/3frYv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3frYv.png" alt="enter image description here" /></a></p>
  <h3>My Pipeline YML File:</h3>
  <pre class="lang-yaml prettyprint-override"><code>trigger:
    - develop
    - master
  
  variables:
    nodeModulesCache: $(System.DefaultWorkingDirectory)/node_modules
  
  stages:
    - stage: client_qa
      displayName: Client code QA
      dependsOn: []
      pool:
        name: Default
      jobs:
        - job:
          displayName: Lint &amp; test client code
          steps:
            # Use NodeJS.
            - task: UseNode@1
              inputs:
                version: &quot;12.x&quot;
  
            # Restore cache.
            - task: Cache@2
              inputs:
                key: 'npm | &quot;$(Agent.OS)&quot; | client/package-lock.json'
                restoreKeys: |
                  npm | &quot;$(Agent.OS)&quot;
                path: $(nodeModulesCache)
              displayName: Cache Node modules
  
            # Install dependencies.
            - script: npm install
              workingDirectory: client
              displayName: &quot;Install packages&quot;
  
            # Lint affected code.
            - script: npm run lint:affected:ci
              workingDirectory: client
              displayName: &quot;Lint affected code&quot;
  
            # Test affected code.
            - script: npm run test:affected:ci
              workingDirectory: client
              displayName: &quot;Run affected unit tests&quot;
  
  </code></pre>