Skip to main content

CachedReader

Struct CachedReader 

Source
pub struct CachedReader<K: Ord, R: ?Sized> { /* private fields */ }
Expand description

An async read-through adapter over a RangeReader.

Implementations§

Source§

impl<K: Ord, R: ?Sized> CachedReader<K, R>

Source

pub fn new(source: Arc<R>, cache: RangeCache<K>, config: ReaderConfig) -> Self

Wraps source with the provided cache and concurrency policy.

Source

pub const fn cache(&self) -> &RangeCache<K>

Returns the shared cache.

Source

pub const fn source(&self) -> &Arc<R>

Returns the wrapped source.

Source

pub const fn config(&self) -> ReaderConfig

Returns the reader configuration.

Source§

impl<K, R> CachedReader<K, R>
where K: Ord + Clone, R: RangeReader<K> + ?Sized,

Source

pub async fn read( &self, key: &K, range: Range<usize>, ) -> Result<Bytes, ReadError<R::Error>>

Reads a range, fetching and caching only its missing gaps.

Identical in-flight key-and-gap requests share one source fetch. Other overlapping requests remain independent. Responses rejected by the cache capacity policy are still returned to the caller.

§Errors

Returns a validation error, source error, or ReadError::ShortRead. Source failures and invalid response lengths are never cached.

§Panics

Panics only if the privately owned fetch semaphore is unexpectedly closed or an internal read-plan coverage invariant is violated.

Trait Implementations§

Source§

impl<K: Ord, R: ?Sized> Clone for CachedReader<K, R>

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

impl<K, R> RangeReader<K> for CachedReader<K, R>
where K: Ord + Clone + Send + Sync, R: RangeReader<K> + ?Sized,

Source§

type Error = ReadError<<R as RangeReader<K>>::Error>

Source-specific error.
Source§

fn read_range<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, range: Range<usize>, ) -> Pin<Box<dyn Future<Output = Result<Bytes, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reads the requested byte range for key.

Auto Trait Implementations§

§

impl<K, R> !RefUnwindSafe for CachedReader<K, R>

§

impl<K, R> !UnwindSafe for CachedReader<K, R>

§

impl<K, R> Freeze for CachedReader<K, R>
where R: ?Sized,

§

impl<K, R> Send for CachedReader<K, R>
where R: Sync + Send + ?Sized, K: Send,

§

impl<K, R> Sync for CachedReader<K, R>
where R: Sync + Send + ?Sized, K: Send,

§

impl<K, R> Unpin for CachedReader<K, R>
where R: ?Sized,

§

impl<K, R> UnsafeUnpin for CachedReader<K, R>
where R: ?Sized,

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.