Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
provide fallback cache keys
Browse files Browse the repository at this point in the history
it's a lot faster to start from a 90% correct cache than an empty one

re: actions#286
re: actions#323
re: actions#328
  • Loading branch information
nigelzor committed Feb 28, 2023
1 parent 64ed1c7 commit 3ec743e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73046,8 +73046,9 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
}
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);
const restoreKeys = [`node-cache-${platform}-${packageManager}-`];
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
const cacheKey = yield cache.restoreCache([cachePath], primaryKey);
const cacheKey = yield cache.restoreCache([cachePath], primaryKey, restoreKeys);

This comment has been minimized.

Copy link
@xer0x

xer0x Apr 3, 2023

👏 thanks @nigelzor -- we ran into a problem with setup-node's cache-key today, and I'm delighted to see you here.

This comment has been minimized.

Copy link
@voxpelli

voxpelli Apr 28, 2023

As I noted in actions#323, this can make the cache grow infinitely. I had this setup in a large team project and eventually our cache folder started nearing 1GB in size, causing GitHub to evict a lot of caches due to passing the cache space.

Hence why a rolling timeout is needed with at least npm, to ensure one starts from scratch every once in a while.

core.setOutput('cache-hit', Boolean(cacheKey));
if (!cacheKey) {
core.info(`${packageManager} cache is not found`);
Expand Down
3 changes: 2 additions & 1 deletion src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export const restoreCache = async (

const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);
const restoreKeys = [`node-cache-${platform}-${packageManager}-`];

core.saveState(State.CachePrimaryKey, primaryKey);

const cacheKey = await cache.restoreCache([cachePath], primaryKey);
const cacheKey = await cache.restoreCache([cachePath], primaryKey, restoreKeys);
core.setOutput('cache-hit', Boolean(cacheKey));

if (!cacheKey) {
Expand Down

0 comments on commit 3ec743e

Please sign in to comment.