feat(cache): evict items idle past cache.idle_ttl

Every cached item got a 7-day expiry at store time. A popular tarball
left the cache seven days after it was cached, however often clients
requested it.

Artifacts now get no age-based expiry. Cleanup removes any item whose
last_accessed is older than cache.idle_ttl (default 168h, 0 disables).
It reads the items in bounded batches of 500 through the indexed
last_accessed column and deletes them through deletePackage. Metadata
entries keep the freshness expiry from default_ttl.

Startup and each cleanup run clear the expiry that earlier versions set
on artifact rows. Cleanup records the idle and ttl eviction reasons and
logs the count and bytes freed. The stats API reports idle_ttl in
seconds. Package deletes are soft deletes and no history table has a
foreign key to packages, so download history stays intact.
This commit is contained in:
2026-11-23 12:49:47 +00:00
parent 99c885cd88
commit d6edd40d79
19 changed files with 1059 additions and 39 deletions
+11
View File
@@ -230,6 +230,17 @@ func (m *MockMetadataStore) AggregateDownloadData(ctx context.Context) error {
return args.Error(0)
}
// The idle-eviction queries are not mocked per test: no expiry, no idle rows.
func (m *MockMetadataStore) ListIdlePackages(context.Context, time.Time, int) ([]*metadata.Package, error) {
return nil, nil
}
func (m *MockMetadataStore) ListExpiredPackages(context.Context, time.Time, int) ([]*metadata.Package, error) {
return nil, nil
}
func (m *MockMetadataStore) ClearArtifactExpiry(context.Context) (int64, error) { return 0, nil }
// API key methods are not used by the cache package; stub them out so the
// mock continues to satisfy metadata.MetadataStore after the interface gained
// API key persistence methods.