add cache names and actually serialize

This commit is contained in:
Bryan Stitt 2023-06-07 17:55:34 -07:00
parent 5744b459ee
commit c37b320286
5 changed files with 11 additions and 6 deletions

View File

@ -48,6 +48,7 @@ where
// TODO: prefix instead of a static str
let local_cache = CacheBuilder::new(cache_size.try_into().unwrap())
.time_to_live(Duration::from_secs(ttl))
.name(&format!("DeferredRateLimiter-{}", prefix))
.build();
Self {

View File

@ -400,11 +400,13 @@ impl Web3ProxyApp {
// TODO: max_capacity from config
// TODO: ttl from config
let rpc_secret_key_cache = CacheBuilder::new(10_000)
.name("rpc_secret_key")
.time_to_live(Duration::from_secs(600))
.build();
// TODO: TTL left low, this could also be a solution instead of modifiying the cache, that may be disgusting across threads / slow anyways
let user_balance_cache = CacheBuilder::new(10_000)
.name("user_balance")
.time_to_live(Duration::from_secs(600))
.build();
@ -501,6 +503,7 @@ impl Web3ProxyApp {
// TODO: what should we set? 5 minutes is arbitrary. the nodes themselves hold onto transactions for much longer
// TODO: this used to be time_to_update, but
let pending_transactions = CacheBuilder::new(10_000)
.name("pending_transactions")
.time_to_live(Duration::from_secs(300))
.build();

View File

@ -54,6 +54,7 @@ pub async fn serve(
debug!("response_cache size: {}", response_cache_size);
let response_cache: ResponseCache = CacheBuilder::new(response_cache_size as u64)
.name("frontend_response")
.time_to_live(Duration::from_secs(1))
.build();

View File

@ -168,14 +168,12 @@ impl<'a, K, V> Serialize for MokaCacheSerializer<'a, K, V> {
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("MokaCache", 2)?;
self.0.weighted_size();
let mut state = serializer.serialize_struct("MokaCache", 3)?;
state.serialize_field("entry_count", &self.0.entry_count())?;
state.serialize_field("name", &self.0.name())?;
state.serialize_field("weighted_size", &self.0.weighted_size())?;
todo!();
// state.end()
state.end()
}
}

View File

@ -98,6 +98,7 @@ impl Web3Rpcs {
// TODO: actual weighter on this
// TODO: time_to_idle instead?
let blocks_by_hash: BlocksByHashCache = CacheBuilder::new(1_000)
.name("blocks_by_hash")
.time_to_idle(Duration::from_secs(30 * 60))
.build();
@ -105,6 +106,7 @@ impl Web3Rpcs {
// TODO: limits from config
// TODO: time_to_idle instead?
let blocks_by_number = CacheBuilder::new(1_000)
.name("blocks_by_number")
.time_to_idle(Duration::from_secs(30 * 60))
.build();