Documentation
¶
Overview ¶
Package diskcache holds the pieces of the single-flight, mtime-LRU disk-cache sweep used by the helm render cache (pkg/helm). Entry collection (a recursive file walk) stays in the caller; what's shared here is the single-flight gate that keeps a burst of writes from forking one sweep per write, and the oldest-first eviction loop that deletes entries until total bytes fall under a cap.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EvictOldest ¶
func EvictOldest(entries []Entry, total, limit int64, less func(a, b Entry) int, remove func(e Entry) error)
EvictOldest removes entries oldest-first until the running total is at or below limit. total is the caller's pre-summed byte usage of entries; when it's already within limit nothing is removed. less defines the eviction order (the helm render cache pins mtime then path). remove deletes one entry's path and returns an error on failure; a failed remove is skipped (its bytes stay counted) and the sweep continues, matching the caller's best-effort semantics.
Types ¶
type Entry ¶
Entry is one candidate for eviction: an absolute path, its byte size, and the mtime the LRU order is computed from (unix nanos for a stable total order across the two callers' clock representations).
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate is a single-flight gate for an asynchronous sweep: at most one sweep runs at a time, so a write storm past the cap schedules exactly one eviction pass instead of N. The zero value is ready to use.
func (*Gate) Release ¶
func (g *Gate) Release()
Release clears the busy flag so the next over-cap write can re-trigger. Pair every successful TryAcquire with a Release (defer it in the sweep goroutine).
func (*Gate) TryAcquire ¶
TryAcquire returns true and marks the gate busy when no sweep is in flight, false when one already is. The acquirer owns the gate until it calls Release.