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)
| 226 | // item's TTL is expired. key is the resulting key for req. It's returned to |
| 227 | // avoid recalculating it afterwards. |
| 228 | func (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 |