Skip to content

Commit 537aa19

Browse files
authored
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/
1 parent f70e52d commit 537aa19

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

dist/post_run/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -66447,11 +66447,9 @@ const getIntervalKey = (invalidationIntervalDays) => {
6644766447
function buildCacheKeys() {
6644866448
return __awaiter(this, void 0, void 0, function* () {
6644966449
const keys = [];
66450-
let cacheKey = `golangci-lint.cache-`;
66451-
keys.push(cacheKey);
6645266450
// Periodically invalidate a cache because a new code being added.
6645366451
// TODO: configure it via inputs.
66454-
cacheKey += `${getIntervalKey(7)}-`;
66452+
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`;
6645566453
keys.push(cacheKey);
6645666454
if (yield pathExists(`go.mod`)) {
6645766455
// Add checksum to key to invalidate a cache when dependencies change.

dist/run/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -66447,11 +66447,9 @@ const getIntervalKey = (invalidationIntervalDays) => {
6644766447
function buildCacheKeys() {
6644866448
return __awaiter(this, void 0, void 0, function* () {
6644966449
const keys = [];
66450-
let cacheKey = `golangci-lint.cache-`;
66451-
keys.push(cacheKey);
6645266450
// Periodically invalidate a cache because a new code being added.
6645366451
// TODO: configure it via inputs.
66454-
cacheKey += `${getIntervalKey(7)}-`;
66452+
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`;
6645566453
keys.push(cacheKey);
6645666454
if (yield pathExists(`go.mod`)) {
6645766455
// Add checksum to key to invalidate a cache when dependencies change.

src/cache.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ const getIntervalKey = (invalidationIntervalDays: number): string => {
5252

5353
async function buildCacheKeys(): Promise<string[]> {
5454
const keys = []
55-
let cacheKey = `golangci-lint.cache-`
56-
keys.push(cacheKey)
57-
5855
// Periodically invalidate a cache because a new code being added.
5956
// TODO: configure it via inputs.
60-
cacheKey += `${getIntervalKey(7)}-`
57+
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`
6158
keys.push(cacheKey)
6259

6360
if (await pathExists(`go.mod`)) {

0 commit comments

Comments
 (0)