dataloader

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchFunc

type BatchFunc func(ctx context.Context, keys []interface{}) ([]interface{}, []error)

BatchFunc loads multiple keys and returns their values The returned slice must be the same length as the keys slice

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader batches and caches data loading operations

func NewLoader

func NewLoader(config LoaderConfig, batchFunc BatchFunc) *Loader

NewLoader creates a new DataLoader

func (*Loader) Clear

func (l *Loader) Clear(key interface{})

Clear removes a key from the cache

func (*Loader) ClearAll

func (l *Loader) ClearAll()

ClearAll removes all keys from the cache

func (*Loader) Load

func (l *Loader) Load(ctx context.Context, key interface{}) (interface{}, error)

Load loads a single key, batching and caching the load

func (*Loader) LoadMany

func (l *Loader) LoadMany(ctx context.Context, keys []interface{}) ([]interface{}, error)

LoadMany loads multiple keys at once

func (*Loader) Prime

func (l *Loader) Prime(key interface{}, value interface{})

Prime adds a value to the cache

type LoaderConfig

type LoaderConfig struct {
	// Wait is the duration to wait before dispatching a batch
	Wait time.Duration
	// MaxBatch is the maximum number of keys to load in a single batch
	MaxBatch int
}

LoaderConfig configures a DataLoader

func DefaultLoaderConfig

func DefaultLoaderConfig() LoaderConfig

DefaultLoaderConfig returns default loader configuration

Jump to

Keyboard shortcuts

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