Struct BlockCache
pub struct BlockCache<R> { /* private fields */ }std only.Expand description
A ReadAt wrapper that keeps recently read blocks in memory.
The source is read in fixed-size blocks, held within a byte budget across sharded locks and evicted with the CLOCK algorithm. A read that spans blocks is assembled from them. Reads larger than a quarter of the budget go straight to the source so one large read cannot flush the cache.
The cache assumes the source does not change: the size is captured at construction and cached blocks are never revalidated. Wrap a new cache around a new source when the source is replaced.
Implementations§
§impl<R> BlockCache<R>where
R: ReadAt,
impl<R> BlockCache<R>where
R: ReadAt,
pub fn new(inner: R, config: &BlockCacheConfig) -> Result<BlockCache<R>, Error>
pub fn new(inner: R, config: &BlockCacheConfig) -> Result<BlockCache<R>, Error>
pub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether blocks are kept at all (the budget holds at least one block).
pub fn block_size(&self) -> usize
pub fn block_size(&self) -> usize
The size of one block.
pub fn block(&self, index: u64) -> Result<Bytes, Error>
pub fn block(&self, index: u64) -> Result<Bytes, Error>
The block with index index, shorter than the block size only at the
end of the source.
A cached block is returned without copying. With caching disabled the block is read from the source on every call.
§Errors
Returns io::ErrorKind::UnexpectedEof for a block past the captured
size, or the error of the source.
Trait Implementations§
§impl<R> Debug for BlockCache<R>where
R: Debug,
impl<R> Debug for BlockCache<R>where
R: Debug,
Auto Trait Implementations§
impl<R> !RefUnwindSafe for BlockCache<R>
impl<R> Freeze for BlockCache<R>where
R: Freeze,
impl<R> Send for BlockCache<R>where
R: Send,
impl<R> Sync for BlockCache<R>where
R: Sync,
impl<R> Unpin for BlockCache<R>where
R: Unpin,
impl<R> UnsafeUnpin for BlockCache<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for BlockCache<R>where
R: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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> ⓘ
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> ⓘ
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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more