Expand description
Bounding the on-disk cache with LRU eviction of idle mirrors.
When a byte cap is configured (--cache-max-mb), a CacheIndex tracks every
mirror’s size and access order in memory. The request path only ever does O(1)
bookkeeping against it - never disk IO:
touchon every request (a served cache hit counts as use),mark_changedafter a clone/fetch, flagging the mirror for (re)measurement.
All disk work - measuring a changed mirror’s size, and evicting mirrors - runs
in the background run task, off the critical path, so a client’s clone/fetch
is never blocked by cache maintenance. Access order lives in an lru::LruCache
(a hashmap plus an intrusive list), so touch promotes in O(1) and eviction
pops the least-recently-used tail until back under the cap - no re-sorting. An
evicted mirror is transparently re-cloned on its next request, so eviction is a
cache-management concern only, never a correctness one. With no cap set, no index
is built and the default path keeps its current zero-overhead unbounded-growth
behaviour.
Structs§
- Cache
Index - In-memory record of the on-disk mirror cache, plus the eviction trigger. Shared
(via
Arc) between theGitCachethat mutates it on clone/fetch/serve and the background task inrunthat measures and evicts.
Functions§
- run
- Background maintenance task. Measures changed mirrors and evicts the LRU tail
whenever the index signals work, and exits cleanly when
shutdownfires (or its sender drops).