setup-node icon indicating copy to clipboard operation
setup-node copied to clipboard

Cache prefix key for multiple cache-dependency-path

Open Cellule opened this issue 7 months ago • 1 comments

Description:

Currently the cache key is always the following format node-cache-{platform}-{packageManager}-{fileHash(lockfile)} I'd like a way to add a prefix between the packageManager and the file hash like node-cache-{platform}-{packageManager}-{cachePrefix}-{fileHash(lockfile)}

Justification:

We work in a monorepo with yarn workspaces. In order to scope our yarn installs and cache, we use yarn workspaces focus with cache-dependency-path pointing to yarn.workspace.lock from https://github.com/MaintainX/yarn-plugin-workspace-lockfile

This means we have multiple workflows all saving and restoring caches for different file hashes. Because we use yarn3, setup-node uses fallback restore keys. Which means it frequently happens that 1 workflow will fallback on the cache from a totally different set of lockfiles, run yarn effectively download what's missing and grow the cache and save that cache back.

Somewhat related https://github.com/actions/setup-node/issues/1120

What happens is that our caches are constantly growing, over time including the whole monorepo's dependencies and more. We tried to mitigate this by manually creating caches on push to master using actions/cache/save instead of setup-node so we wouldn't restore the cache making it a "fresh" cache.

Having a cache prefix that we control, we could give a semantic name for scopes of the monorepo allowing to avoid workflows to cross restore caches for a different yarn workspaces focus command

Are you willing to submit a PR?

Yes I'm willing to open a PR if this suggestion is accepted

Cellule avatar Jul 11 '25 13:07 Cellule

Hello @Cellule👋, Thank you for this feature request. We will investigate it and get back to you as soon as we have some feedback.


priya-kinthali avatar Jul 11 '25 14:07 priya-kinthali