Skip to content

Enforce max_size config with LRU cache eviction#102

Merged
andrew merged 1 commit into
mainfrom
enforce-max-size-eviction
Apr 30, 2026
Merged

Enforce max_size config with LRU cache eviction#102
andrew merged 1 commit into
mainfrom
enforce-max-size-eviction

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented Apr 30, 2026

Closes #99.

The max_size storage config was parsed and validated at startup but never enforced. The existing DB queries for LRU eviction (GetLeastRecentlyUsedArtifacts, GetTotalCacheSize, ClearArtifactCache) were already in place but never called.

This adds a background eviction loop that runs every minute when max_size is set. When total cache size exceeds the limit, it evicts least recently used artifacts (deleting from both storage and clearing the DB record) until the cache is back under the limit. When max_size is empty or "0" (unlimited), the loop returns immediately without starting.

Changes:

  • config.ParseMaxSize() converts the max_size string to bytes
  • server/eviction.go implements the eviction loop and evictLRU function
  • server.Start() launches the eviction loop as a background goroutine tied to the existing shutdown context
  • Tests cover: under-limit no-op, LRU ordering, multi-artifact eviction, empty cache, storage file cleanup, and unlimited-skips path

Closes #99. The max_size storage config was parsed and validated but
never enforced. This adds a background eviction loop that periodically
checks total cache size and evicts least recently used artifacts when
the limit is exceeded.
@kpfleming
Copy link
Copy Markdown
Contributor

This looks great!

@andrew andrew merged commit e2495ef into main Apr 30, 2026
5 checks passed
@kpfleming
Copy link
Copy Markdown
Contributor

Just upgraded and within a minute my storage amount dropped from 2.7GB to 1.9GB (configured with max_size of 2GB). :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'max_size' can be specified for storage, but has no effect

2 participants