question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Does Yarn 2 have any sort of global cache?

See original GitHub issue

Describe the user story

Yarn 1 had a useful feature — it stored global cache, for example in folder /usr/local/share/.cache/yarn, which could be revealed by running yarn cache dir.

Having cache like this allowed to mount it to CI runner so that all jobs on runner will have shared cache, and it will be much faster rather than to cache Yarn’s cache per-job.

Yarn 2 does not have such command.

Describe the solution you’d like

Same thing as before. Global cache which will be used as fallback if project’s .yarn/cache is empty.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
kirill-konshincommented, May 20, 2020

@phuctm97 in my case yarn config get cacheFolder returns me %PROJECT_DIR%/.yarn/cache which is project’s folder, not system-wide cache folder.

@arcanis I think this issue has to be reopened, since it will give a lot of benefits for CI like Gitlab. There’s still no solution how to determine which system-wide folder Yarn 2 is using. enableGlobalCache is a bit different, I need both:

  1. local cache (to cache it using Gitlab, per branch)
  2. global cache (same as in Yarn 1) to speed up when local cache is cold (first checkout of branch).
3reactions
phuctm97commented, May 17, 2020

@kirill-konshin I share the same use case with you that I want to be able to save/attach cache to optimize CI/CD resources.

I ended up caching Yarn’s local cache folder and everything works just fine. Why don’t you do that, is there any complication or unseen issue, or you just didn’t think of it?

Following is how I cache Yarn’s local cache folder and the results:

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      node-version: 12.x
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Node.js ${{ env.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ env.node-version }}
      - id: find-yarn-cache-folder
        name: Find Yarn's cache folder
        run: echo "::set-output name=path::$(yarn config get cacheFolder)"
      - name: Cache Yarn's cache folder
        uses: actions/cache@v1
        with:
          path: ${{ steps.find-yarn-cache-folder.outputs.path }}
          key: yarn-cache-folder-os-${{ runner.os }}-node-${{ env.node-version }}-${{ hashFiles('yarn.lock') }}
          restore-keys: |
            yarn-cache-folder-os-${{ runner.os }}-node-${{ env.node-version }}-
            yarn-cache-folder-os-${{ runner.os }}-
      - name: Install dependencies
        run: yarn install
        ...
  • Before applying cache:

    441 packages were already cached, 1556 had to be fetched
    
  • After applying cache:

    1994 packages were already cached
    

Updated CI/CD still bundles my application properly and saves ~85% build time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Offline Cache | Yarn - Package Manager
An overview of Yarn's offline cache, a feature that allows Yarn to work just fine even should the network go down for any...
Read more >
Yarn 2 — the future of package managers for JavaScript? - Snyk
Yarn 2 ticks a quite a few check-boxes on the board that have been keeping developers discussing on how to manage JavaScript projects:...
Read more >
Introducing Yarn 2 ! - DEV Community ‍ ‍
New features will be developed exclusively against Yarn 2. ... if the cache becomes part of your repository then you never need to...
Read more >
Building a Monorepo with Yarn 2 - Heroku Blog
We will cover taking advantage of Yarn 2's cache to manage ... Your JavaScript server has source code, but there's an additional front...
Read more >
Yarn 2 needs proper support in builds - Features
Currently Netlify does a few things that are bad for Yarn 2 users: Caches the node_modules ... every single build (one from Netlify...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found