Skip to content

Commit dd05e8d

Browse files
committed
🎨 Use sleep instead of interval to avoid saving DNS cache at statup
1 parent 010ee65 commit dd05e8d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/dns_mw_cache.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,16 @@ impl DnsCacheMiddleware {
5151
if cache_file.exists() {
5252
cache.lock().await.load(cache_file.as_path());
5353
}
54-
let mut interval =
55-
tokio::time::interval(Duration::from_secs(cache_checkpoint_time));
54+
let interval = Duration::from_secs(cache_checkpoint_time);
5655
loop {
5756
tokio::select! {
58-
_ = interval.tick() => {
57+
_ = tokio::time::sleep(interval) => {
5958
cache.lock().await.persist(cache_file.as_path());
60-
log::debug!("save cache to {}", cache_file.display());
59+
log::debug!("save DNS cache to file {}", cache_file.display());
6160
}
6261
_ = crate::signal::terminate() => {
6362
cache.lock().await.persist(cache_file.as_path());
64-
log::debug!("save cache to {}", cache_file.display());
63+
log::debug!("save DNS cache to file {}", cache_file.display());
6564
break;
6665
}
6766
};

0 commit comments

Comments
 (0)