Skip to content

Commit 23fd88d

Browse files
committed
feat(storcaching.rs): Implement cleanup hysteresis
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 0f93bac commit 23fd88d

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/storcaching.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,28 @@ async fn clean_disk(cache_dir: String) {
9090
delete_cache_file(oldest_file.file);
9191
}
9292

93+
/// Cache housekeeping loop
94+
/// This function will check the disk space every and clean with some hysteresis
9395
pub async fn cache_loop(cache_dir: &str) {
96+
let mut cleaning_on : bool = false;
9497
loop {
9598
let free_space = freediskspace_percent(cache_dir.to_string()).await;
96-
if free_space < 10 {
97-
println!("Low disk space: {}%", free_space);
99+
if free_space < 12 && !cleaning_on {
100+
cleaning_on = true;
101+
println!("Free disk is LOW: {}%, cleaning is on", free_space);
102+
}
103+
if free_space > 13 && cleaning_on {
104+
cleaning_on = false;
105+
println!("Free disk space is OK: {}%, cleaning is off", free_space);
106+
}
107+
108+
if cleaning_on {
98109
clean_disk(cache_dir.to_string()).await;
99110
// critical mode, sleep only 100ms
100111
tokio::time::sleep(Duration::from_millis(100)).await;
101112
} else {
102113
println!("Free disk space: {}%", free_space);
103-
// sleep for 10 seconds before checking again
114+
// normal mode, sleep 10 seconds
104115
tokio::time::sleep(Duration::from_secs(10)).await;
105116
}
106117
}

0 commit comments

Comments
 (0)