From 4e63e69c97f784d4866f9bc1642c1dc8bd633784 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 9 Feb 2023 11:55:39 -0800 Subject: [PATCH] actually use app.response_cache_max_bytes --- web3_proxy/src/app/mod.rs | 8 +++----- web3_proxy/src/config.rs | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 5f977fed..75610ca2 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -669,14 +669,12 @@ impl Web3ProxyApp { )); } - // keep 1GB of blocks in the cache - // responses can be very different in sizes, so this definitely needs a weigher - // TODO: max_capacity from config + // responses can be very different in sizes, so this is a cache with a max capacity and a weigher // TODO: don't allow any response to be bigger than X% of the cache let response_cache = Cache::builder() - .max_capacity(1024 * 1024 * 1024) + .max_capacity(top_config.app.response_cache_max_bytes) .weigher(|k: &ResponseCacheKey, v| { - // TODO: is this good? + // TODO: is this good enough? if let Ok(v) = serde_json::to_string(v) { let weight = k.weight() + v.len(); diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index 567c14d9..942632e7 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -138,7 +138,7 @@ pub struct AppConfig { /// RPC responses are cached locally #[serde(default = "default_response_cache_max_bytes")] - pub response_cache_max_bytes: usize, + pub response_cache_max_bytes: u64, /// the stats page url for an anonymous user. pub redirect_public_url: Option, @@ -190,10 +190,10 @@ fn default_login_rate_limit_per_period() -> u64 { 10 } -fn default_response_cache_max_bytes() -> usize { +fn default_response_cache_max_bytes() -> u64 { // TODO: default to some percentage of the system? // 100 megabytes - 10_usize.pow(8) + 10u64.pow(8) } /// Configuration for a backend web3 RPC server