mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-05 03:16:03 +03:00
Correct cache behavior
This commit is contained in:
parent
d2e79c281d
commit
83cffab45f
@ -52,18 +52,19 @@ var (
|
||||
)
|
||||
|
||||
func QueryRecord(domain string, server string) (string, error) {
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
rec, found := dnsCache[domain]
|
||||
if found && rec.expire.After(time.Now()) {
|
||||
return "", nil
|
||||
return rec.record, nil
|
||||
}
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
record, err := dohQuery(server, domain)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
rec.record = record
|
||||
rec.expire = time.Now().Add(time.Second * 600)
|
||||
dnsCache[domain] = rec
|
||||
return record, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user