pub struct MerkleCacheStore { /* private fields */ }Expand description
Redis cache for SQL Merkle tree.
This is a dumb cache - no tree computation happens here. All tree logic (hashing, bubble-up) is handled by SqlMerkleStore.
Implementations§
Source§impl MerkleCacheStore
impl MerkleCacheStore
Sourcepub fn new(conn: ConnectionManager) -> Self
pub fn new(conn: ConnectionManager) -> Self
Create a new cache store without a prefix.
Sourcepub fn with_prefix(conn: ConnectionManager, prefix: Option<&str>) -> Self
pub fn with_prefix(conn: ConnectionManager, prefix: Option<&str>) -> Self
Create a new cache store with an optional prefix.
Sourcepub fn key_prefix(&self) -> &str
pub fn key_prefix(&self) -> &str
Get the prefix used for all merkle keys.
Sourcepub async fn get_hash(
&self,
path: &str,
) -> Result<Option<[u8; 32]>, StorageError>
pub async fn get_hash( &self, path: &str, ) -> Result<Option<[u8; 32]>, StorageError>
Get the hash for a path (root = “”).
Sourcepub async fn root_hash(&self) -> Result<Option<[u8; 32]>, StorageError>
pub async fn root_hash(&self) -> Result<Option<[u8; 32]>, StorageError>
Get the root hash (path = “”).
Sourcepub async fn get_children(
&self,
path: &str,
) -> Result<BTreeMap<String, [u8; 32]>, StorageError>
pub async fn get_children( &self, path: &str, ) -> Result<BTreeMap<String, [u8; 32]>, StorageError>
Get children of an interior node.
Sourcepub async fn get_node(
&self,
path: &str,
) -> Result<Option<MerkleNode>, StorageError>
pub async fn get_node( &self, path: &str, ) -> Result<Option<MerkleNode>, StorageError>
Get a full node (hash + children).
Sourcepub async fn cache_node(
&self,
path: &str,
hash: [u8; 32],
children: &BTreeMap<String, [u8; 32]>,
) -> Result<(), StorageError>
pub async fn cache_node( &self, path: &str, hash: [u8; 32], children: &BTreeMap<String, [u8; 32]>, ) -> Result<(), StorageError>
Copy a node from SQL to this cache.
Called after SQL merkle batch completes. Copies both hash and children.
Sourcepub async fn delete_node(&self, path: &str) -> Result<(), StorageError>
pub async fn delete_node(&self, path: &str) -> Result<(), StorageError>
Delete a node from cache.
Sourcepub async fn sync_from_sql(
&self,
sql_store: &SqlMerkleStore,
) -> Result<usize, StorageError>
pub async fn sync_from_sql( &self, sql_store: &SqlMerkleStore, ) -> Result<usize, StorageError>
Sync entire SQL merkle tree to cache.
Useful on startup or after cache invalidation. Reads all nodes from SQL and copies to Redis.
Sourcepub async fn sync_affected_from_sql(
&self,
sql_store: &SqlMerkleStore,
affected_paths: &[String],
) -> Result<usize, StorageError>
pub async fn sync_affected_from_sql( &self, sql_store: &SqlMerkleStore, affected_paths: &[String], ) -> Result<usize, StorageError>
Sync only affected paths from SQL to cache.
More efficient than full sync for incremental updates. Syncs the leaves, their ancestors, and the root.
Trait Implementations§
Source§impl Clone for MerkleCacheStore
impl Clone for MerkleCacheStore
Source§fn clone(&self) -> MerkleCacheStore
fn clone(&self) -> MerkleCacheStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MerkleCacheStore
impl !RefUnwindSafe for MerkleCacheStore
impl Send for MerkleCacheStore
impl Sync for MerkleCacheStore
impl Unpin for MerkleCacheStore
impl !UnwindSafe for MerkleCacheStore
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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