MCPcopy
hub / github.com/AdguardTeam/dnsproxy / get

Method get

proxy/cache.go:228–247  ·  view source on GitHub ↗

get returns cached item for the req if it's found. expired is true if the item's TTL is expired. key is the resulting key for req. It's returned to avoid recalculating it afterwards.

(req *dns.Msg)

Source from the content-addressed store, hash-verified

226// item's TTL is expired. key is the resulting key for req. It's returned to
227// avoid recalculating it afterwards.
228func (c *cache) get(req *dns.Msg) (ci *cacheItem, expired bool, key []byte) {
229 c.itemsLock.RLock()
230 defer c.itemsLock.RUnlock()
231
232 if !canLookUpInCache(c.items, req) {
233 return nil, false, nil
234 }
235
236 key = msgToKey(req)
237 data := c.items.Get(key)
238 if data == nil {
239 return nil, false, key
240 }
241
242 if ci, expired = c.unpackItem(data, req); ci == nil {
243 c.items.Del(key)
244 }
245
246 return ci, expired, key
247}
248
249// getWithSubnet returns cached item for the req if it's found by n. expired
250// is true if the item's TTL is expired. k is the resulting key for req. It's

Callers 10

replyFromCacheMethod · 0.80
TestCache_expiredFunction · 0.80
TestCacheDOFunction · 0.80
TestCacheCNAMEFunction · 0.80
TestCache_uncacheableFunction · 0.80
TestCacheExpirationFunction · 0.80
runMethod · 0.80
setAndGetCacheFunction · 0.80

Calls 3

unpackItemMethod · 0.95
canLookUpInCacheFunction · 0.85
msgToKeyFunction · 0.85

Tested by 9

TestCache_expiredFunction · 0.64
TestCacheDOFunction · 0.64
TestCacheCNAMEFunction · 0.64
TestCache_uncacheableFunction · 0.64
TestCacheExpirationFunction · 0.64
runMethod · 0.64
setAndGetCacheFunction · 0.64