MCPcopy
hub / github.com/coredns/coredns / tryPrefetch

Method tryPrefetch

plugin/cache/handler.go:104–113  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
104func (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
115func (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.

Callers 1

ServeDNSMethod · 0.95

Calls 2

doPrefetchMethod · 0.95

Tested by

no test coverage detected