mirror of
https://github.com/sadoyan/aralez.git
synced 2026-11-24 21:59:07 +08:00
Add max cache item size.
This commit is contained in:
Vendored
+6
-2
@@ -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,
|
||||
|
||||
Vendored
+2
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user