mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-22 19:33:32 +02:00
Correct cache behavior
This commit is contained in:
parent
d2e79c281d
commit
83cffab45f
1 changed files with 4 additions and 3 deletions
|
@ -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