pub struct CacheIndex { /* private fields */ }Expand description
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.
Implementations§
Source§impl CacheIndex
impl CacheIndex
Sourcepub fn new(
cache_root: PathBuf,
max_bytes: u64,
metrics: Arc<Metrics>,
) -> Arc<Self> ⓘ
pub fn new( cache_root: PathBuf, max_bytes: u64, metrics: Arc<Metrics>, ) -> Arc<Self> ⓘ
Build the index by scanning cache_root once. Seeds access order from each
mirror’s newest file mtime (oldest first, so the oldest lands at the LRU
tail), so recency roughly survives a restart. Blocking, but runs at startup
before the server binds.
Sourcepub fn touch(&self, name: &str)
pub fn touch(&self, name: &str)
Mark a repo used. Serving does not grow the cache, so this never wakes the
evictor; it only keeps the access order honest. No-op for a repo not yet
tracked (its first clone tracks it via mark_changed).
Sourcepub fn record_blob(&self, key: &str, size: u64)
pub fn record_blob(&self, key: &str, size: u64)
Record a cached LFS object with its exact size and wake the background task in case the cache is now over cap. Unlike a mirror, an object is immutable and its size is known at store time, so it needs no deferred measurement - it goes straight into the index at its final size and is promoted to most-recently-used.
Sourcepub fn mark_changed(&self, name: &str)
pub fn mark_changed(&self, name: &str)
Flag a mirror as changed after a clone/fetch: promote it (it was just used), schedule it for measurement, and wake the background task. O(1) bookkeeping only - the size walk happens off the request path.