From 537aa1903e5d359d0b27dbc19ddd22c5087f3fbc Mon Sep 17 00:00:00 2001 From: Eric Zimanyi Date: Wed, 11 May 2022 00:30:26 -0400 Subject: [PATCH] Expire cache periodically to avoid unbounded size (#466) * Expire cache periodically to avoid unbounded size The cache key includes a sequence number that rotates every 7 days but because we are also using the base `golangci-lint.cache` as a restore key, the new cache will always be seeded with the full contents of the old cache. In particular for the go module cache, this leads to an ever increasing number of cached packages that never get pruned. This commit updates it so we stop using `golangci-lint.cache` as a restore key, which will force a build from an empty cache once every 7 days. * Rebuild files in dist/ --- dist/post_run/index.js | 4 +--- dist/run/index.js | 4 +--- src/cache.ts | 5 +---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/dist/post_run/index.js b/dist/post_run/index.js index b53c63cc94..cac14aa280 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -66447,11 +66447,9 @@ const getIntervalKey = (invalidationIntervalDays) => { function buildCacheKeys() { return __awaiter(this, void 0, void 0, function* () { const keys = []; - let cacheKey = `golangci-lint.cache-`; - keys.push(cacheKey); // Periodically invalidate a cache because a new code being added. // TODO: configure it via inputs. - cacheKey += `${getIntervalKey(7)}-`; + let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`; keys.push(cacheKey); if (yield pathExists(`go.mod`)) { // Add checksum to key to invalidate a cache when dependencies change. diff --git a/dist/run/index.js b/dist/run/index.js index df050f044b..fd5dee7009 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -66447,11 +66447,9 @@ const getIntervalKey = (invalidationIntervalDays) => { function buildCacheKeys() { return __awaiter(this, void 0, void 0, function* () { const keys = []; - let cacheKey = `golangci-lint.cache-`; - keys.push(cacheKey); // Periodically invalidate a cache because a new code being added. // TODO: configure it via inputs. - cacheKey += `${getIntervalKey(7)}-`; + let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`; keys.push(cacheKey); if (yield pathExists(`go.mod`)) { // Add checksum to key to invalidate a cache when dependencies change. diff --git a/src/cache.ts b/src/cache.ts index c29f29542d..a06f33f5e6 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -52,12 +52,9 @@ const getIntervalKey = (invalidationIntervalDays: number): string => { async function buildCacheKeys(): Promise { const keys = [] - let cacheKey = `golangci-lint.cache-` - keys.push(cacheKey) - // Periodically invalidate a cache because a new code being added. // TODO: configure it via inputs. - cacheKey += `${getIntervalKey(7)}-` + let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-` keys.push(cacheKey) if (await pathExists(`go.mod`)) {