pub struct PackIndexCache { /* private fields */ }Expand description
In-process LRU cache of decoded pack indices keyed by
(prefix, content-sha).
Capacity is bounded by byte size, not entry count: a single 1 GB pack carries an .idx file of multiple MiB, so an entry-count cap would either over- or under-budget for realistic chains. Eviction is least-recently-used.
The cache is Send + Sync and shareable across read_blob calls.
Multiple concurrent calls block briefly on the inner mutex during
lookup / insert; the inflate / range-GET work happens outside the
lock so contention stays bounded.
§LRU bookkeeping cost
get and insert walk the order VecDeque via iter().position
to move the touched key to the back — O(n) in the cache size.
For typical packchain workloads (single-digit indices in flight),
the constant factor dominates and this is faster than a true O(1)
linked-list LRU. If a workload starts seeing hundreds of cached
indices, this should be revisited (e.g. swap to the lru crate or
hand-roll a HashMap + intrusive doubly-linked list). The simple
shape is intentional for now.
§Example
use git_remote_object_store::{packchain::PackIndexCache, Remote};
let remote = Remote::connect("s3+https://bucket/repo?engine=packchain").await?;
let cache = PackIndexCache::default();
let bytes = git_remote_object_store::packchain::read_blob(
&remote,
"refs/heads/main",
"src/main.rs",
&cache,
).await?;
println!("{}", String::from_utf8_lossy(&bytes));Implementations§
Source§impl PackIndexCache
impl PackIndexCache
Sourcepub fn new(capacity_bytes: u64) -> Self
pub fn new(capacity_bytes: u64) -> Self
Construct a cache with the requested byte budget.
capacity_bytes of zero disables caching (every lookup misses).
Use Self::default for the standard 64 MiB budget.
Sourcepub fn resident_bytes(&self) -> u64
pub fn resident_bytes(&self) -> u64
Total resident bytes accounted for by the cache.
§Panics
Panics only if a previous holder of the inner mutex panicked while mutating cache state — an invariant violation that would be unsafe to silently recover from.
Trait Implementations§
Source§impl Debug for PackIndexCache
impl Debug for PackIndexCache
Auto Trait Implementations§
impl !Freeze for PackIndexCache
impl RefUnwindSafe for PackIndexCache
impl Send for PackIndexCache
impl Sync for PackIndexCache
impl Unpin for PackIndexCache
impl UnsafeUnpin for PackIndexCache
impl UnwindSafe for PackIndexCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more