Add optional cache to SqlMerkleRadixStore
This change adds an optional cache field to the SqlMerkleRadixStore.
As this struct is public, and may be constructed by library consumers,
the cache is optional, and only accessible from within the crate.
@@ -29,6 +29,8 @@ mod sqlite;
use std::collections::HashSet;
use crate::error::InternalError;
+#[cfg(feature = "state-merkle-sql-caching")]
+use crate::state::merkle::sql::cache::DataCache;
use crate::state::merkle::{node::Node, sql::backend::Backend};
// (Hash, packed bytes, path address)
@@ -233,11 +235,25 @@ pub trait MerkleRadixStore {
/// A MerkleRadixStore backed by a SQL back-end.
pub struct SqlMerkleRadixStore<'b, B: Backend> {
pub backend: &'b B,
+ #[cfg(feature = "state-merkle-sql-caching")]
+ pub cache: Option<&'b DataCache>,
}
impl<'b, B: Backend> SqlMerkleRadixStore<'b, B> {
/// Constructs a new store for a given back-end.
pub fn new(backend: &'b B) -> Self {
- Self { backend }
+ Self {
+ backend,
+ #[cfg(feature = "state-merkle-sql-caching")]
+ cache: None,
+ }
+ }
+
+ #[cfg(feature = "state-merkle-sql-caching")]
+ pub(crate) fn new_with_cache(backend: &'b B, cache: &'b DataCache) -> Self {
+ Self {
+ backend,
+ cache: Some(cache),
+ }
}
}
