pub struct ChunkCache { /* private fields */ }Expand description
LRU cache for decompressed chunks.
Thread-safe via parking_lot::Mutex (non-poisoning). Values are
Arc<Vec<u8>> so multiple readers can share the same decompressed chunk data.
Implementations§
Source§impl ChunkCache
impl ChunkCache
Sourcepub fn new(max_bytes: usize, max_slots: usize) -> Self
pub fn new(max_bytes: usize, max_slots: usize) -> Self
Create a new chunk cache.
max_bytes: maximum total bytes of decompressed data to cache (default 64 MiB)max_slots: maximum number of entries (default 521)
Sourcepub fn get(&self, key: &ChunkKey) -> Option<Arc<Vec<u8>>>
pub fn get(&self, key: &ChunkKey) -> Option<Arc<Vec<u8>>>
Get a cached chunk, if present. Promotes the entry in LRU order.
Sourcepub fn insert(&self, key: ChunkKey, data: Vec<u8>) -> Arc<Vec<u8>> ⓘ
pub fn insert(&self, key: ChunkKey, data: Vec<u8>) -> Arc<Vec<u8>> ⓘ
Insert a chunk into the cache. Evicts LRU entries if over capacity.
Sourcepub fn get_or_insert_with<F>(
&self,
key: ChunkKey,
load: F,
) -> Result<Arc<Vec<u8>>>
pub fn get_or_insert_with<F>( &self, key: ChunkKey, load: F, ) -> Result<Arc<Vec<u8>>>
Return a cached chunk or compute it once across concurrent callers.
Sourcepub fn stats(&self) -> ChunkCacheStats
pub fn stats(&self) -> ChunkCacheStats
Return current cache statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ChunkCache
impl !RefUnwindSafe for ChunkCache
impl Send for ChunkCache
impl Sync for ChunkCache
impl Unpin for ChunkCache
impl UnsafeUnpin for ChunkCache
impl !UnwindSafe for ChunkCache
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> 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 more