Fix: mapping dns should not stale (#675)

* Fix: mapping dns should not stale

* Update enhancer.go
This commit is contained in:
YuSaki丶Kanade 2023-08-01 17:30:57 +08:00 committed by GitHub
parent f125e1ce9e
commit b0fed73236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -109,7 +109,7 @@ func NewEnhancer(cfg Config) *ResolverEnhancer {
if cfg.EnhancedMode != C.DNSNormal {
fakePool = cfg.Pool
mapping = cache.New(cache.WithSize[netip.Addr, string](4096), cache.WithStale[netip.Addr, string](true))
mapping = cache.New(cache.WithSize[netip.Addr, string](4096))
}
return &ResolverEnhancer{

View File

@ -129,6 +129,10 @@ func withMapping(mapping *cache.LruCache[netip.Addr, string]) middleware {
continue
}
if ttl < 1 {
ttl = 1
}
mapping.SetWithExpire(ip, host, time.Now().Add(time.Second*time.Duration(ttl)))
}