Skip to content

Commit

Permalink
Randomize LRU cache cycle start pos
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Mar 19, 2024
1 parent 7b8c60b commit 2a79458
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 2a79458

Please sign in to comment.