Skip to content

Commit

Permalink
add hot reload for cache in init.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
kfatyuip committed Aug 5, 2024
1 parent 2a3f239 commit 0945838
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/init.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0945838

Please sign in to comment.