pub struct ProxyCache {
pub entries: Vec<CacheEntry>,
pub max_size_bytes: u64,
pub used_bytes: u64,
}Expand description
In-memory proxy cache with configurable capacity.
Fields§
§entries: Vec<CacheEntry>All cached entries.
max_size_bytes: u64Maximum allowed total size of the cache in bytes.
used_bytes: u64Current total size of all entries in bytes.
Implementations§
Source§impl ProxyCache
impl ProxyCache
Sourcepub fn add(&mut self, path: &str, size: u64, now_ms: u64)
pub fn add(&mut self, path: &str, size: u64, now_ms: u64)
Add a new entry to the cache.
If an entry with the same path already exists it is replaced and the used-byte count is updated accordingly.
Sourcepub fn touch(&mut self, path: &str, now_ms: u64) -> bool
pub fn touch(&mut self, path: &str, now_ms: u64) -> bool
Update the access timestamp and hit count for an entry.
Returns true if the entry was found and updated.
Sourcepub fn evict_lru(&mut self) -> Option<String>
pub fn evict_lru(&mut self) -> Option<String>
Remove the least-recently-used entry and return its path.
Returns None if the cache is empty.
Sourcepub fn evict_stale(&mut self, now_ms: u64, ttl_ms: u64) -> Vec<String>
pub fn evict_stale(&mut self, now_ms: u64, ttl_ms: u64) -> Vec<String>
Remove all entries that are stale (last access older than ttl_ms).
Returns the paths of all evicted entries.
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Cache utilisation as a fraction in [0.0, 1.0].
Returns 0.0 when max_size_bytes is 0.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ProxyCache
impl RefUnwindSafe for ProxyCache
impl Send for ProxyCache
impl Sync for ProxyCache
impl Unpin for ProxyCache
impl UnsafeUnpin for ProxyCache
impl UnwindSafe for ProxyCache
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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