Mercury/src/cache/sweep.rs
Matthew L McPeak a289f7a23e
Some checks failed
ci / test (push) Failing after 6s
ci / build-ui (push) Successful in 13s
ci / publish (push) Has been skipped
Initial Commit
2026-06-17 19:55:23 -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);
}
});
}