Skip to main content

ChunkCache

Struct ChunkCache 

Source
pub struct ChunkCache { /* private fields */ }
Expand description

A per-dataset chunk cache with hash-based index and LRU eviction.

§Usage

let cache = ChunkCache::new();
// Pass &cache to read_chunked_data — it will populate the index lazily.

The cache is wrapped in Mutex internally so it can be mutated through shared references (thread-safe).

Implementations§

Source§

impl ChunkCache

Source

pub fn new() -> Self

Create a new chunk cache with default limits (1 MiB, 16 slots).

Source

pub fn with_capacity(max_bytes: usize, max_slots: usize) -> Self

Create a new chunk cache with custom byte budget and slot count.

Source

pub fn has_index(&self) -> bool

Returns true if the chunk index has been built.

Source

pub fn populate_index(&self, chunks: &[ChunkInfo], rank: usize)

Build the chunk index from a pre-collected list of ChunkInfo.

The rank parameter is used to truncate offsets to spatial dims only (B-tree v1 stores rank+1 offsets).

Source

pub fn lookup_index(&self, coord: &[u64]) -> Option<ChunkInfo>

Look up a chunk by its spatial coordinate in the index.

Source

pub fn all_indexed_chunks(&self) -> Option<Vec<ChunkInfo>>

Return all indexed chunks as a Vec<ChunkInfo> (order unspecified).

Source

pub fn get_decompressed(&self, coord: &[u64]) -> Option<Vec<u8>>

Try to get cached decompressed data for a chunk coordinate.

Returns a clone of the cache-line-aligned buffer.

Source

pub fn get_decompressed_aligned( &self, coord: &[u64], ) -> Option<CacheAlignedBuffer>

Try to get a reference-counted clone of the aligned buffer for a chunk.

Source

pub fn put_decompressed(&self, coord: ChunkCoord, data: Vec<u8>)

Insert decompressed chunk data into the LRU cache.

The data is stored in a CacheAlignedBuffer so subsequent reads return cache-line-aligned memory.

Source

pub fn put_decompressed_aligned( &self, coord: ChunkCoord, data: CacheAlignedBuffer, )

Insert an already-aligned buffer into the LRU cache.

Source

pub fn clear(&self)

Clear the entire cache (index + decompressed data).

Source

pub fn prefetch_hint(&self, next_coords: &[ChunkCoord])

Hint that the given chunk coordinates will be accessed soon.

Pre-populates the chunk index for these coordinates so that subsequent lookups are O(1). This does NOT pre-decompress the chunks — it only ensures the index entries exist.

Source

pub fn access_stats(&self) -> AccessStats

Return the current access pattern statistics.

Source

pub fn set_sweep_direction(&self, direction: &'static str)

Update the sweep direction label in the access stats.

Source

pub fn cached_chunk_count(&self) -> usize

Number of decompressed chunks currently cached.

Source

pub fn cached_bytes(&self) -> usize

Total bytes of decompressed data currently cached.

Trait Implementations§

Source§

impl Default for ChunkCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.