Add max cache item size.

This commit is contained in:
Ara Sadoyan
2026-10-23 15:27:23 +02:00
parent 56c41e2c19
commit 72756a00dd
8 changed files with 32 additions and 6 deletions
+6 -2
View File
@@ -170,9 +170,13 @@ impl Storage for RedisCache {
let (internal_bytes, header_bytes) = meta.serialize()?;
let mut conn = (*self.client).clone();
let _: RedisResult<()> = conn.set_ex(&internal_key, &internal_bytes, ttl).await;
let _: RedisResult<()> = conn.set_ex(&header_key, &header_bytes, ttl).await;
if let Err(e) = conn.set_ex::<_, _, ()>(&internal_key, &internal_bytes, ttl).await {
log::error!("Failed to cache body to Redis: {}", e);
}
if let Err(e) = conn.set_ex::<_, _, ()>(&header_key, &header_bytes, ttl).await {
log::error!("Failed to cache headers to Redis: {}", e);
}
Ok(Box::new(RedisMissHandler {
client: self.client.clone(),
body_key,
+2 -1
View File
@@ -21,7 +21,8 @@ pub async fn init_cache(config: Arc<AppConfig>) {
CACHE_TTL.set(ttl).ok();
if let Some(size) = config.cache_size_mb {
let cache_size = size * 1024 * 1024;
drop(EVICTION.set(Manager::new(cache_size)));
let manager = Manager::new(cache_size);
let _ = EVICTION.set(manager);
}
GLOBAL_STORAGE.set(Box::new(MemCache::new())).ok();
info!("Cache initialized successfully. Storage: {}", cache_storage);