pub struct DiskBoundedCache { /* private fields */ }Expand description
A disk-space-bounded LRU proxy cache that automatically evicts entries when the configured space limit would be exceeded.
Unlike the simpler ProxyCache, DiskBoundedCache:
- Enforces a hard disk-space ceiling on insertions.
- Uses LRU eviction automatically upon every insertion that would violate the limit.
- Maintains hit/miss/eviction counters for telemetry.
- Supports lookup with automatic LRU touch.
Implementations§
Source§impl DiskBoundedCache
impl DiskBoundedCache
Sourcepub fn new(max_bytes: u64) -> Result<Self, String>
pub fn new(max_bytes: u64) -> Result<Self, String>
Create a new cache with a disk-space limit of max_bytes.
§Errors
Returns a descriptive string if max_bytes is zero.
Sourcepub fn insert(&mut self, path: &str, size_bytes: u64, now_ms: u64) -> bool
pub fn insert(&mut self, path: &str, size_bytes: u64, now_ms: u64) -> bool
Insert a proxy entry identified by path with size_bytes and access time now_ms.
If an entry with the same path already exists it is updated in-place (moved to the
MRU end). Before inserting, LRU entries are evicted until the new entry fits within
the space limit. If the single entry itself is larger than the limit, the insert
is rejected and false is returned.
Returns true when the entry was inserted/updated, false when it was rejected.
Sourcepub fn access(&mut self, path: &str, now_ms: u64) -> Option<CacheEntry>
pub fn access(&mut self, path: &str, now_ms: u64) -> Option<CacheEntry>
Look up a cache entry by path.
On hit: moves the entry to the MRU position and updates access time. On miss: increments the miss counter.
Returns a clone of the entry on hit, or None on miss.
Sourcepub fn evict_lru(&mut self) -> Option<String>
pub fn evict_lru(&mut self) -> Option<String>
Remove and return the path of the least-recently-used entry.
Returns None if the cache is empty.
Sourcepub fn used_bytes(&self) -> u64
pub fn used_bytes(&self) -> u64
Current total used bytes.
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Cache utilisation fraction in [0.0, 1.0].
Sourcepub fn stats(&self) -> DiskCacheStats
pub fn stats(&self) -> DiskCacheStats
Collect and return a statistics snapshot.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DiskBoundedCache
impl RefUnwindSafe for DiskBoundedCache
impl Send for DiskBoundedCache
impl Sync for DiskBoundedCache
impl Unpin for DiskBoundedCache
impl UnsafeUnpin for DiskBoundedCache
impl UnwindSafe for DiskBoundedCache
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