mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-27 11:01:27 +00: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 a new issue