pub struct BlockCache<R> { /* private fields */ }Expand description
Block-based caching layer that wraps any RangeReader.
This cache is critical for performance:
- TIFF parsing requires many small reads at scattered offsets
- Without caching, each read would be an S3 request
- Block cache amortizes these into fewer, larger requests
Features:
- Fixed-size block cache (default 256KB blocks)
- LRU eviction when cache reaches capacity
- Singleflight: concurrent requests for the same block share one fetch
- Handles reads spanning multiple blocks
Implementations§
Source§impl<R: RangeReader> BlockCache<R>
impl<R: RangeReader> BlockCache<R>
Sourcepub fn new(inner: R) -> Self
pub fn new(inner: R) -> Self
Create a new BlockCache wrapping the given reader.
Uses default block size (256KB) and cache capacity (100 blocks).
Sourcepub fn with_capacity(inner: R, block_size: usize, capacity: usize) -> Self
pub fn with_capacity(inner: R, block_size: usize, capacity: usize) -> Self
Create a new BlockCache with custom block size and capacity.
§Arguments
inner- The underlying reader to wrapblock_size- Size of each cached block in bytescapacity- Maximum number of blocks to cache
Trait Implementations§
Source§impl<R: RangeReader + 'static> RangeReader for BlockCache<R>
impl<R: RangeReader + 'static> RangeReader for BlockCache<R>
Source§fn read_exact_at<'life0, 'async_trait>(
&'life0 self,
offset: u64,
len: usize,
) -> Pin<Box<dyn Future<Output = Result<Bytes, IoError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn read_exact_at<'life0, 'async_trait>(
&'life0 self,
offset: u64,
len: usize,
) -> Pin<Box<dyn Future<Output = Result<Bytes, IoError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn identifier(&self) -> &str
fn identifier(&self) -> &str
Get a unique identifier for this resource (for logging and cache keys). Read more
Auto Trait Implementations§
impl<R> !Freeze for BlockCache<R>
impl<R> !RefUnwindSafe for BlockCache<R>
impl<R> Send for BlockCache<R>
impl<R> Sync for BlockCache<R>
impl<R> Unpin for BlockCache<R>
impl<R> !UnwindSafe for BlockCache<R>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.