Skip to content

Commit

Permalink
🎨 Use sleep instead of interval to avoid saving DNS cache at statup
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyish committed Oct 10, 2024
1 parent 010ee65 commit dd05e8d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/dns_mw_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ impl DnsCacheMiddleware {
if cache_file.exists() {
cache.lock().await.load(cache_file.as_path());
}
let mut interval =
tokio::time::interval(Duration::from_secs(cache_checkpoint_time));
let interval = Duration::from_secs(cache_checkpoint_time);
loop {
tokio::select! {
_ = interval.tick() => {
_ = tokio::time::sleep(interval) => {
cache.lock().await.persist(cache_file.as_path());
log::debug!("save cache to {}", cache_file.display());
log::debug!("save DNS cache to file {}", cache_file.display());
}
_ = crate::signal::terminate() => {
cache.lock().await.persist(cache_file.as_path());
log::debug!("save cache to {}", cache_file.display());
log::debug!("save DNS cache to file {}", cache_file.display());
break;
}
};
Expand Down

0 comments on commit dd05e8d

Please sign in to comment.