Skip to main content

Module evict

Module evict 

Source
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:

  • touch on every request (a served cache hit counts as use),
  • mark_changed after 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§

CacheIndex
In-memory record of the on-disk mirror cache, plus the eviction trigger. Shared (via Arc) between the GitCache that mutates it on clone/fetch/serve and the background task in run that 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 shutdown fires (or its sender drops).