Skip to main content

RangeCache

Struct RangeCache 

Source
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>

Source

pub fn new(capacity: CacheCapacity) -> Self

Creates an empty cache with an explicit capacity policy.

Source

pub const fn capacity(&self) -> CacheCapacity

Returns the configured capacity policy.

Source§

impl<K: Ord + Clone> RangeCache<K>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&self) -> Invalidation

Removes every resident range while retaining accumulated statistics.

Source

pub fn snapshot(&self) -> CacheSnapshot

Returns a consistent snapshot of cache state and lifetime statistics.

Trait Implementations§

Source§

impl<K> Clone for RangeCache<K>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<K> !RefUnwindSafe for RangeCache<K>

§

impl<K> !UnwindSafe for RangeCache<K>

§

impl<K> Freeze for RangeCache<K>

§

impl<K> Send for RangeCache<K>
where K: Send,

§

impl<K> Sync for RangeCache<K>
where K: Send,

§

impl<K> Unpin for RangeCache<K>

§

impl<K> UnsafeUnpin for RangeCache<K>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.