mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-15 01:09:20 +02: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) {
|
func QueryRecord(domain string, server string) (string, error) {
|
||||||
mutex.RLock()
|
|
||||||
defer mutex.RUnlock()
|
|
||||||
rec, found := dnsCache[domain]
|
rec, found := dnsCache[domain]
|
||||||
if found && rec.expire.After(time.Now()) {
|
if found && rec.expire.After(time.Now()) {
|
||||||
return "", nil
|
return rec.record, nil
|
||||||
}
|
}
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
record, err := dohQuery(server, domain)
|
record, err := dohQuery(server, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
rec.record = record
|
rec.record = record
|
||||||
rec.expire = time.Now().Add(time.Second * 600)
|
rec.expire = time.Now().Add(time.Second * 600)
|
||||||
|
dnsCache[domain] = rec
|
||||||
return record, nil
|
return record, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue