fixed-cache

This commit is contained in:
Arsenii Kulikov
2025-12-19 02:06:32 +04:00
parent 567f389d31
commit 01935968e1
3 changed files with 14 additions and 7 deletions

10
Cargo.lock generated
View File

@@ -3986,6 +3986,15 @@ dependencies = [
"windows-sys 0.60.2",
]
[[package]]
name = "fixed-cache"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e0b787b8055e984fefc8a6a0709fc800d374dcb2794017799c0f245c75322d4"
dependencies = [
"equivalent",
]
[[package]]
name = "fixed-hash"
version = "0.8.0"
@@ -8243,6 +8252,7 @@ dependencies = [
"dashmap 6.1.0",
"derive_more",
"eyre",
"fixed-cache",
"futures",
"metrics",
"metrics-util",

View File

@@ -54,6 +54,7 @@ tokio = { workspace = true, features = ["rt", "rt-multi-thread", "sync", "macros
mini-moka = { workspace = true, features = ["sync"] }
moka = { workspace = true, features = ["sync"] }
smallvec.workspace = true
fixed-cache = "0.1.1"
# metrics
metrics.workspace = true

View File

@@ -31,7 +31,7 @@ where
/// Cache for precompiles, for each input stores the result.
#[derive(Debug, Clone)]
pub struct PrecompileCache<S>(
moka::sync::Cache<Bytes, CacheEntry<S>, alloy_primitives::map::DefaultHashBuilder>,
Arc<fixed_cache::Cache<Bytes, CacheEntry<S>, alloy_primitives::map::DefaultHashBuilder>>,
)
where
S: Eq + Hash + std::fmt::Debug + Send + Sync + Clone + 'static;
@@ -41,11 +41,7 @@ where
S: Eq + Hash + std::fmt::Debug + Send + Sync + Clone + 'static,
{
fn default() -> Self {
Self(
moka::sync::CacheBuilder::new(MAX_CACHE_SIZE as u64)
.initial_capacity(MAX_CACHE_SIZE as usize)
.build_with_hasher(Default::default()),
)
Self(Arc::new(fixed_cache::Cache::new(MAX_CACHE_SIZE as usize, Default::default())))
}
}
@@ -60,7 +56,7 @@ where
/// Inserts the given key and value into the cache, returning the new cache size.
fn insert(&self, input: Bytes, value: CacheEntry<S>) -> usize {
self.0.insert(input, value);
self.0.entry_count() as usize
MAX_CACHE_SIZE as usize
}
}