简体   繁体   中英

Does the npm cache speed up `npm install`?

Consider the following builds:

These two repositories are almost identical, with the only difference being the latter repository caches npm via the setup-node GitHub Action, whereas the former one does not. In other words, the only difference between the repositories is at the .github/workflows/main file:

name: Build Pipeline
on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '11'
          # Following line is present only on the latter repository
          cache: 'npm'
      - run: npm install
      - run: npm run build

Although the build at "setup-node-with-cache" successfully uses npm cache (as evident by the output of the Run actions/setup-node@v2 step), run time of Run npm install step is almost the same as the corresponding step of the build at "setup-node-without-cache".

Isn't the run time of Run npm install step of the build at "setup-node-with-cache" supposed to be significantly shorter than the corresponding step of the build at "setup-node-without-cache", since it is supposed to use the cached npm packages? Am I missing something here?

It really does not seem to be, at least on GitHub Actions. The workaround that I found is caching the actual node_modules folder, even though it is "not recommended". Caching the actual node_modules folder does speed up npm install .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM