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.
This commit is contained in:
Eric Zimanyi 2022-05-07 14:11:31 -04:00 committed by Sergey Vilgelm
parent f70e52dcc9
commit d93ab869ca
No known key found for this signature in database
GPG key ID: 08D0E2FF778887E6

View file

@ -52,12 +52,9 @@ const getIntervalKey = (invalidationIntervalDays: number): string => {
async function buildCacheKeys(): Promise<string[]> { async function buildCacheKeys(): Promise<string[]> {
const keys = [] const keys = []
let cacheKey = `golangci-lint.cache-`
keys.push(cacheKey)
// Periodically invalidate a cache because a new code being added. // Periodically invalidate a cache because a new code being added.
// TODO: configure it via inputs. // TODO: configure it via inputs.
cacheKey += `${getIntervalKey(7)}-` let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`
keys.push(cacheKey) keys.push(cacheKey)
if (await pathExists(`go.mod`)) { if (await pathExists(`go.mod`)) {