tryPrefetch dispatches a background prefetch for i if one is not already in flight. The CAS on i.refreshing ensures at most one prefetch goroutine per item, so prefetch load scales with distinct stale keys rather than QPS.
(ctx context.Context, i *item, server string, req *dns.Msg, do, cd bool, now time.Time)
| 102 | // flight. The CAS on i.refreshing ensures at most one prefetch goroutine per |
| 103 | // item, so prefetch load scales with distinct stale keys rather than QPS. |
| 104 | func (c *Cache) tryPrefetch(ctx context.Context, i *item, server string, req *dns.Msg, do, cd bool, now time.Time) { |
| 105 | if !i.refreshing.CompareAndSwap(false, true) { |
| 106 | return |
| 107 | } |
| 108 | cw := newPrefetchResponseWriter(server, req, do, cd, c) |
| 109 | go func() { |
| 110 | defer i.refreshing.Store(false) |
| 111 | c.doPrefetch(ctx, cw, i, now) |
| 112 | }() |
| 113 | } |
| 114 | |
| 115 | func (c *Cache) doPrefetch(ctx context.Context, cw *ResponseWriter, i *item, now time.Time) { |
| 116 | // Use a fresh metadata map to avoid concurrent writes to the original request's metadata. |
no test coverage detected