Mercury/src/cache/sweep.rs
Matthew L McPeak dd700d02ad
All checks were successful
ci / build-ui (push) Successful in 14s
ci / test (push) Successful in 3m50s
ci / publish (push) Successful in 3m9s
Inital Commit
2026-07-16 12:36:14 -04:00

15 lines
515 B
Rust

use crate::state::QueryCache;
use std::time::Duration;
pub fn spawn_sweep_task(cache: QueryCache, idle_timeout_secs: u64, sweep_interval_secs: u64) {
tokio::spawn(async move {
let interval = Duration::from_secs(sweep_interval_secs);
loop {
tokio::time::sleep(interval).await;
let now = crate::state::unix_now();
cache
.map
.retain(|_, entry| now.saturating_sub(entry.last_accessed()) < idle_timeout_secs);
}
});
}