setWithSubnet stores response and upstream with subnet in the cache. The given subnet mask and IP address are used to calculate the cache key. u, n, and l must not be nil.
(req, m *dns.Msg, u upstream.Upstream, n *net.IPNet, l *slog.Logger)
| 347 | // given subnet mask and IP address are used to calculate the cache key. u, n, |
| 348 | // and l must not be nil. |
| 349 | func (c *cache) setWithSubnet(req, m *dns.Msg, u upstream.Upstream, n *net.IPNet, l *slog.Logger) { |
| 350 | item := c.respToItem(m, u, l) |
| 351 | if item == nil { |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | pref, _ := n.Mask.Size() |
| 356 | key := msgToKeyWithSubnet(req, n.IP.Mask(n.Mask), pref) |
| 357 | packed := item.pack() |
| 358 | |
| 359 | c.itemsWithSubnetLock.Lock() |
| 360 | defer c.itemsWithSubnetLock.Unlock() |
| 361 | |
| 362 | c.itemsWithSubnet.Set(key, packed) |
| 363 | } |
| 364 | |
| 365 | // clearItems empties the simple cache. |
| 366 | func (c *cache) clearItems() { |