actually use app.response_cache_max_bytes

This commit is contained in:
Bryan Stitt 2023-02-09 11:55:39 -08:00
parent 5ffe2aa72a
commit 4e63e69c97
2 changed files with 6 additions and 8 deletions

@ -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();

@ -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<String>,
@ -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