Skip to main content

TreeNodeCache

Struct TreeNodeCache 

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

In-process LRU cache of TreeNode postcard-encoded bytes. Keyed by BLAKE3 hash; bytes-bounded eviction.

Caller wraps this in a Mutex for shared access. Single- owner hot loops can use it unsynchronised.

Implementations§

Source§

impl TreeNodeCache

Source

pub fn new() -> Self

Construct a cache with the default 64 MiB cap.

Source

pub fn with_capacity_bytes(cap_bytes: usize) -> Self

Construct a cache with an explicit byte cap. cap_bytes == 0 disables caching — every get misses, every insert is a no-op. Useful for ablation testing or for callers that want explicit cache disable.

Source

pub fn get(&mut self, hash: &[u8; 32]) -> Option<Bytes>

Look up hash. On hit, returns a Bytes clone of the cached entry (Bytes::clone is one atomic refcount bump, not a memcpy of the node payload) and promotes the entry to most-recently-used. On miss, returns None.

Source

pub fn len(&self) -> usize

Number of entries currently cached.

Source

pub fn is_empty(&self) -> bool

true iff no entries are cached.

Source

pub fn bytes(&self) -> usize

Current total byte payload across all cached entries.

Source

pub fn cap_bytes(&self) -> usize

Configured byte cap.

Source

pub fn hits(&self) -> u64

Lifetime hit counter.

Source

pub fn misses(&self) -> u64

Lifetime miss counter.

Source

pub fn hit_ratio(&self) -> f64

Hit ratio in [0.0, 1.0], or 0.0 when no accesses have happened. Useful for operator dashboards.

Source

pub fn clear(&mut self)

Drop every entry. Resets hit / miss counters.

Source

pub fn remove(&mut self, hash: &[u8; 32])

Drop a single entry by hash. Used by the chunk-delete / GC sweep paths to keep the cache in sync with the on-disk chunk store: a manifest node whose chunk file just went away must not survive in cache, otherwise subsequent fetch_range walks descend through the cached node and only discover the missing chunks at the leaf, confusing operator error attribution. Cache integrity (bytes hash to key) is preserved either way — this fix is for error- path clarity, not for soundness.

No-op if the hash isn’t cached.

Trait Implementations§

Source§

impl Debug for TreeNodeCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TreeNodeCache

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more