Documentation
¶
Overview ¶
Package coalesce provides request coalescing to prevent duplicate upstream fetches.
When multiple concurrent requests arrive for the same cache key, the coalescer ensures only one upstream fetch is performed while other requests wait for the result. This prevents cache stampedes and reduces load on upstream servers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Coalescer ¶
type Coalescer struct {
// contains filtered or unexported fields
}
Coalescer handles request coalescing for identical requests using singleflight.
func (*Coalescer) Fetch ¶
Fetch performs a fetch operation with coalescing If another goroutine is already fetching the same key, this will wait for completion Otherwise, it will call fetchFn to fetch from upstream and signal all waiters when done.
func (*Coalescer) FetchDetect ¶ added in v1.41.0
func (c *Coalescer) FetchDetect(ctx context.Context, key string, fetchFn FetchFunc) (leader, coalesced bool, err error)
FetchDetect behaves like Fetch but also reports whether this caller ran the fetch fn (leader) and whether the singleflight group was shared with other concurrent callers (coalesced). Used by the dry-run middleware to observe what caching + coalescing would have done without actually caching.