coalesce

package
v1.40.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 3 Imported by: 0

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 New

func New() *Coalescer

New creates a new Coalescer.

func (*Coalescer) Fetch

func (c *Coalescer) Fetch(ctx context.Context, key string, fetchFn FetchFunc) error

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.

type FetchFunc

type FetchFunc func(ctx context.Context) error

FetchFunc is a function that fetches data from upstream and stores it It should return nil on success, or an error if the fetch failed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL