From 094583829680d48dd546562d45c69d9f6b80d7b8 Mon Sep 17 00:00:00 2001 From: Kieran Moy Date: Tue, 6 Aug 2024 00:24:19 +0800 Subject: [PATCH] add hot reload for cache in init.rs --- src/init.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/init.rs b/src/init.rs index dc12596..1f5cb37 100644 --- a/src/init.rs +++ b/src/init.rs @@ -1,11 +1,11 @@ use crate::config::{init_config, CONFIG, DEFAULT_CONFIG, DEFAULT_TICK}; -use anyhow::Result; use async_mutex::Mutex; use async_rwlock::RwLock; use lazy_static::lazy_static; use log4rs::Handle; use lru::LruCache; use signal_hook::{consts::SIGHUP, iterator::Signals}; +use std::num::NonZero; use std::{env::set_current_dir, io, num::NonZeroUsize, sync::Arc, thread}; #[cfg(feature = "log")] @@ -167,6 +167,20 @@ pub async fn init_signal() -> io::Result<()> { } } + let cache = config.server.cache.unwrap_or_default(); + let (index_capacity, file_capacity) = + (cache.index_capacity.unwrap(), cache.file_capacity.unwrap()); + + INDEX_CACHE + .lock() + .await + .resize(NonZero::new(index_capacity).unwrap()); + + FILE_CACHE + .lock() + .await + .resize(NonZero::new(file_capacity).unwrap()); + let mut t = T.write().await; *t = None; drop(t);