pub struct RangeCache<K> { /* private fields */ }Expand description
A cloneable, thread-safe sparse cache of byte ranges keyed by K.
Implementations§
Source§impl<K> RangeCache<K>
impl<K> RangeCache<K>
Sourcepub fn new(capacity: CacheCapacity) -> Self
pub fn new(capacity: CacheCapacity) -> Self
Creates an empty cache with an explicit capacity policy.
Sourcepub const fn capacity(&self) -> CacheCapacity
pub const fn capacity(&self) -> CacheCapacity
Returns the configured capacity policy.
Source§impl<K: Ord + Clone> RangeCache<K>
impl<K: Ord + Clone> RangeCache<K>
Sourcepub fn get(
&self,
key: &K,
range: Range<usize>,
) -> Result<Option<Bytes>, RangeError>
pub fn get( &self, key: &K, range: Range<usize>, ) -> Result<Option<Bytes>, RangeError>
Returns the requested bytes when the entire range is cached.
A hit contained in one resident range returns a zero-copy Bytes
slice. Empty ranges always succeed.
§Errors
Returns RangeError::ReversedRange when range.end < range.start.
Sourcepub fn missing_ranges(
&self,
key: &K,
range: Range<usize>,
) -> Result<Vec<Range<usize>>, RangeError>
pub fn missing_ranges( &self, key: &K, range: Range<usize>, ) -> Result<Vec<Range<usize>>, RangeError>
Returns the gaps within range that are not resident for key.
§Errors
Returns RangeError::ReversedRange when range.end < range.start.
Sourcepub fn insert(
&self,
key: K,
range: Range<usize>,
bytes: Bytes,
) -> Result<InsertOutcome, RangeError>
pub fn insert( &self, key: K, range: Range<usize>, bytes: Bytes, ) -> Result<InsertOutcome, RangeError>
Inserts bytes for range, merging adjacent and overlapping ranges.
An insert wholly contained by one existing range is ignored. Otherwise, inserted bytes replace overlapping bytes while cached prefix and suffix bytes remain intact.
§Errors
Returns RangeError::ReversedRange for a reversed range or
RangeError::PayloadLengthMismatch when the payload length differs
from the range length.
§Panics
Panics only if an internal range-map, LRU, or byte-accounting invariant has been violated.
Sourcepub fn invalidate(&self, key: &K) -> Invalidation
pub fn invalidate(&self, key: &K) -> Invalidation
Removes all ranges associated with key.
§Panics
Panics only if an internal range-map, LRU, or byte-accounting invariant has been violated.
Sourcepub fn clear(&self) -> Invalidation
pub fn clear(&self) -> Invalidation
Removes every resident range while retaining accumulated statistics.
Sourcepub fn snapshot(&self) -> CacheSnapshot
pub fn snapshot(&self) -> CacheSnapshot
Returns a consistent snapshot of cache state and lifetime statistics.