Skip to content

Commit

Permalink
fix(cache): Trigger cacache to remove expired contents (#28275)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
4 people committed Apr 9, 2024
1 parent e0115f9 commit fcfbf38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/util/cache/package/file.spec.ts
Expand Up @@ -30,8 +30,14 @@ describe('util/cache/package/file', () => {
await set('_test-namespace', 'valid', 1234);
await set('_test-namespace', 'expired', 1234, -5);
await cacache.put(cacheFileName, 'invalid', 'not json');
const expiredDigest = (
await cacache.get(cacheFileName, '_test-namespace-expired')
).integrity;
await cleanup();
const entries = await cacache.ls(cacheFileName);
expect(Object.keys(entries)).toEqual(['_test-namespace-valid']);
await expect(
cacache.get.byDigest(cacheFileName, expiredDigest),
).rejects.toThrow('ENOENT');
});
});
2 changes: 2 additions & 0 deletions lib/util/cache/package/file.ts
Expand Up @@ -99,6 +99,8 @@ export async function cleanup(): Promise<void> {
deletedCount += 1;
}
}
logger.debug(`Verifying and cleaning cache: ${cacheFileName}`);
await cacache.verify(cacheFileName);
const durationMs = Math.round(Date.now() - startTime);
logger.debug(
`Deleted ${deletedCount} of ${totalCount} file cached entries in ${durationMs}ms`,
Expand Down

0 comments on commit fcfbf38

Please sign in to comment.