setup-node: github action cache not working

Description: When I run the code below, I confirmed that the cache is created in management.

name: ESLint Check

on: push

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - run: npm ci

      - name: Run ESLint
        run: npm run lint

On the second run, cache-hit returns true, but it still takes a long time because it reinstalls dependencies.

The link below says that the machine’s global cache is used. How does the machine’s global cache work? global cache

Action version: Specify the action version

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 17
  • Comments: 24 (3 by maintainers)

Most upvoted comments

I, too, have tried usingsetup-node’s caching, but it did not reduce my build times.

I then tried using actions/cache directly, caching the path ~/.npm. This significantly sped up my build time, as expected.

      - uses: actions/cache@v3
        with:
          path: '~/.npm'
          key: ${{ runner.os }}-${{ matrix.node-version }}-9.8.0-npmcache-${{ hashFiles('**/package-lock.json') }}

Something I noticed, my successful cache was 510 MB, but the setup-node cache is only 38 MB.

Screenshot 2023-08-01 at 5 02 30 pm

So I think I get what it’s supposed to cache now. However, it don’t work at all as you’d expect; enable caching then continue to install your dependencies as usual. Then on the subsequent passes the installs will be much faster since the global cache data would be restored, and not HTTP calls would be made. However that never happens.

I have the same issue as the OP @enKODING1 and others. I feel I’m missing something here. “caching global packages data” is not clear. If it were indeed caching then when installing modules it wouldn’t take several minutes anymore. Has someone figured this one out or is the workaround to use actions/cache directly?