15 lines
515 B
Rust
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);
|
|
}
|
|
});
|
|
}
|