Cache optimization using pnpm, next and nx
Unanswered
Giant panda posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
I'm using a monorepo solution called nx to manage several next apps. I also use github actions to run my CIs and I'm struggling to cache properly my builds.
Here's the relevant workflow steps:
But I keep running into warning messages in builds about no caches and stuff.
EDIT:
Here's the warning message:
Does anyone have any experience in that?
Thanks!
Here's the relevant workflow steps:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm & next caches
with:
path: |
${{ env.STORE_PATH }}
${{ github.workspace }}/dist/
# Generate a new cache whenever packages or source files change or prisma model changes.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.[jt]s', '**/*.[jt]sx', '**/*.prisma') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
But I keep running into warning messages in builds about no caches and stuff.
EDIT:
Here's the warning message:
warn No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
Does anyone have any experience in that?
Thanks!
23 Replies
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
can you share the exact warning message?
and your full action file if possible
and btw, cache can't be overwritten, so you should add
github.workspace
to your cache keythat error is because your not caching the
.next/cache
folder (made by nextjs)![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
Thanks for your answers.
The
The
dist/
directory consists of nextjs apps that each contain the .next directory. Should I explicitly list them?![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
so what is
github.workspace
in this contextand you should be not caching things that are in the code themself - waistful
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
it's the root of the nx monorepo project
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
and then where is your building of nextjs
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
I don't know if you're familiar with nx, but basically nx builds and outputs all the apps builds into the
dist/
directory![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
as it would make the most sense to use matrix to build them all and create individual cache for each
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
and more specifically under
dist/apps/app-a/...
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
yeah i don't fully know it
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
No worries 🙂
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
so, it copies your code to dist?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
it outputs the built code to dist under a specific folder, relevant to the app yeah
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
as most systems would do
apps/app-a/dist
and thats whats messing with me
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
well, nx is special lol
what would the matrix look like?
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
like it would be manually running each of the apps individually (but at the same time), so you prob would loose nx features
so, i use turbo repo and it can cache folders inside your app project and save it to a global cache that can be used, does nx have something like it?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Giant pandaOP
unfortunately not, i'll do some research and come back with an answer hopefully