Add an atomic.Bool to singleflight prefetching (#7963)

Also updated plugin to document single-flighting

Signed-off-by: Ryan Brewster <rpb@anthropic.com>
This commit is contained in:
rpb-ant
2026-03-30 16:18:24 -04:00
committed by GitHub
parent 0ba8e3c850
commit 20626a7464
4 changed files with 113 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package cache
import (
"strings"
"sync/atomic"
"time"
"github.com/coredns/coredns/plugin/cache/freq"
@@ -25,6 +26,14 @@ type item struct {
stored time.Time
*freq.Freq
// refreshing is set via CAS when a prefetch goroutine is dispatched for
// this item and cleared when it returns, bounding in-flight prefetches
// per item to one. A successful prefetch replaces this item in the cache
// with a new one (zero-valued refreshing); the deferred clear matters
// only when the prefetch fails and this item remains cached, so the next
// hit can retry.
refreshing atomic.Bool
}
func newItem(m *dns.Msg, now time.Time, d time.Duration) *item {