Skip to main content

CacheDirectory

Struct CacheDirectory 

Source
pub struct CacheDirectory<S = DefaultHashBuilder> { /* private fields */ }

Implementations§

Source§

impl CacheDirectory<DefaultHashBuilder>

Source

pub fn new() -> Self

Construct an empty cache using the default per-process-randomized hasher.

Source§

impl<S: BuildHasher> CacheDirectory<S>

Source

pub fn with_hasher(hasher: S) -> Self
where S: Clone,

Construct an empty cache with an explicit hasher.

Source§

impl<S> CacheDirectory<S>

Source

pub const fn new_const(blobs_hasher: S, instances_hasher: S) -> Self

const fn constructor for static initialisation. Used by the guest’s state_cache::CACHE static. Takes both hashers separately because const fn can’t call S::clone() and not every BuildHasher (notably foldhash::fast::FixedState) implements Copy. Callers normally pass two identically-seeded instances so both maps hash to the same buckets.

Source§

impl<S: BuildHasher> CacheDirectory<S>

Source

pub fn blob_count(&self) -> usize

Number of blob entries.

Source

pub fn instance_count(&self) -> usize

Number of instance entries (live or unswept).

Source

pub fn contains_blob(&self, hash: &CapHash) -> bool

Whether the blobs tier holds an entry under hash.

Source

pub fn get_blob(&self, hash: &CapHash) -> Option<Arc<Cap>>

Get an Arc::clone of the blob cap at hash, or None if absent.

Source

pub fn get_instance(&self, capref: &CapRef) -> Option<Arc<Cap>>

Get an Arc::clone of the instance cap at capref, or None if absent.

Source

pub fn iter_blobs(&self) -> Vec<(CapHash, Arc<Cap>)>

Snapshot the blob tier into a Vec<(CapHash, Arc<Cap>)>. Order is unspecified (HashMap iteration); callers that need deterministic order (state-root computations) sort by hash.

Source

pub fn get(&self, key: CapHashOrRef) -> Option<Arc<Cap>>

Polymorphic lookup that dispatches on the CapHashOrRef arm. Returns an Arc::clone of the matching cap.

Source

pub fn set_instance( &self, capref: &CapRef, new_arc: Arc<Cap>, ) -> Result<(), CacheError>

Replace the instance at capref with a fresh Arc<Cap>. The old Arc<Cap> drops outside the lock (so any cascading Cap::drop → CapRef::drop chain doesn’t try to re-enter the directory while we hold the guard).

Source

pub fn put_cap(&self, cap: &Cap) -> Result<CapHash, CacheError>

Hash + insert into blobs. Idempotent: re-puts of identical content are a no-op. Returns the content hash.

Source

pub fn put_cap_with_hash( &self, hash: CapHash, cap: &Cap, ) -> Result<(), CacheError>

Pre-hashed insert. Debug-asserts the claimed hash matches the cap; release trusts the caller (the SSZ merkleize is the hot cost on the publish path).

Source

pub fn put_instance(&self, cap: Cap) -> CapRef

Insert a freshly-built Cap as a new instance entry. Returns the CapRef handle. The directory keeps its own clone of the returned handle internally as the entry’s self-reference; when all external clones drop, sweep_instances will reclaim the entry.

Source

pub fn promote_blob_to_instance(&self, hash: &CapHash) -> Option<CapRef>

Lazily promote a blob to a fresh instance entry. The blob and the new instance entry share the same Arc<Cap> (no Cap data deep-copy); the next Arc::make_mut call on either side clones-on-write if both still hold the Arc.

Returns None if the blob isn’t published.

Source

pub fn sweep_instances(&self)

GC pass. Walk the instances tier and remove every entry whose stored CapRef has strong_count == 1 (the directory is the sole holder — no external CapRef clone exists). Loop until a pass finds nothing to remove, so cascading drops can orphan more entries which then get reclaimed in the next iteration.

Cycles are structurally impossible (data-flow principle), so the loop is guaranteed to terminate.

Source

pub fn settle(&self, key: CapHashOrRef) -> Result<CapHash, CacheError>

Settle a Ref-keyed working entry: walk nested Ref targets, resolve each to a Hash, then hash the surviving cap. Non- Instance entries (Data / CNode) graduate from instances to blobs under the computed hash; Instance entries stay in instances (they’re the live mutable state) and the returned hash is a snapshot identifier.

For Hash-keyed input, returns it unchanged.

Trait Implementations§

Source§

impl Default for CacheDirectory<DefaultHashBuilder>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S = DefaultHashBuilder> !Freeze for CacheDirectory<S>

§

impl<S = DefaultHashBuilder> !RefUnwindSafe for CacheDirectory<S>

§

impl<S> Send for CacheDirectory<S>
where S: Send,

§

impl<S> Sync for CacheDirectory<S>
where S: Send,

§

impl<S> Unpin for CacheDirectory<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for CacheDirectory<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for CacheDirectory<S>
where S: UnwindSafe,

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
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
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.