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>
impl<K: Ord, R: ?Sized> CachedReader<K, R>
Sourcepub fn new(source: Arc<R>, cache: RangeCache<K>, config: ReaderConfig) -> Self
pub fn new(source: Arc<R>, cache: RangeCache<K>, config: ReaderConfig) -> Self
Wraps source with the provided cache and concurrency policy.
Sourcepub const fn cache(&self) -> &RangeCache<K>
pub const fn cache(&self) -> &RangeCache<K>
Returns the shared cache.
Sourcepub const fn config(&self) -> ReaderConfig
pub const fn config(&self) -> ReaderConfig
Returns the reader configuration.
Source§impl<K, R> CachedReader<K, R>
impl<K, R> CachedReader<K, R>
Sourcepub async fn read(
&self,
key: &K,
range: Range<usize>,
) -> Result<Bytes, ReadError<R::Error>>
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, R> RangeReader<K> for CachedReader<K, R>
impl<K, R> RangeReader<K> for CachedReader<K, R>
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>
impl<K, R> Sync for CachedReader<K, R>
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> 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