Enforce max_size config with LRU cache eviction#102
Merged
Conversation
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.
Contributor
|
This looks great! |
Contributor
|
Just upgraded and within a minute my storage amount dropped from 2.7GB to 1.9GB (configured with max_size of 2GB). :-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #99.
The
max_sizestorage 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_sizeis 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. Whenmax_sizeis empty or"0"(unlimited), the loop returns immediately without starting.Changes:
config.ParseMaxSize()converts themax_sizestring to bytesserver/eviction.goimplements the eviction loop andevictLRUfunctionserver.Start()launches the eviction loop as a background goroutine tied to the existing shutdown context