From 2a79458a8500e85b7ff7587378be5ac23ef965fd Mon Sep 17 00:00:00 2001 From: james58899 Date: Tue, 19 Mar 2024 18:39:18 +0000 Subject: [PATCH] Randomize LRU cache cycle start pos --- src/cache_manager.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cache_manager.rs b/src/cache_manager.rs index cc63d37..ab230d4 100644 --- a/src/cache_manager.rs +++ b/src/cache_manager.rs @@ -20,6 +20,7 @@ use log::{debug, error, info, warn}; use mime::Mime; use openssl::sha::Sha1; use parking_lot::{Mutex, RwLock}; +use rand::{thread_rng, Rng}; use tempfile::TempPath; use tokio::{ fs::{copy, create_dir_all, metadata, read_dir, remove_dir_all, remove_file, rename, DirEntry, File}, @@ -92,7 +93,7 @@ impl CacheManager { cache_dir: cache_dir.as_ref().to_path_buf(), cache_date: Mutex::new(BTreeSet::new()), lru_cache: RwLock::new(vec![]), - lru_clear_pos: Mutex::new(0), + lru_clear_pos: Mutex::new(thread_rng().gen_range(0..LRU_SIZE)), temp_dir: temp_dir.as_ref().to_path_buf(), total_size: Arc::new(AtomicU64::new(0)), size_limit: AtomicU64::new(u64::MAX),