dataloaden

package module
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataLoader

type DataLoader[K comparable, V any] interface {
	// Load a User by key, batching and caching will be applied automatically
	Load(key K) (*V, error)

	// LoadThunk returns a function that when called will block waiting for a User.
	// This method should be used if you want one goroutine to make requests to many
	// different data loaders without blocking until the thunk is called.
	LoadThunk(key K) func() (*V, error)

	// LoadAll fetches many keys at once. It will be broken into appropriate sized
	// sub batches depending on how the loader is configured
	LoadAll(keys []K) ([]*V, []error)

	// LoadAllThunk returns a function that when called will block waiting for a Users.
	// This method should be used if you want one goroutine to make requests to many
	// different data loaders without blocking until the thunk is called.
	LoadAllThunk(keys []K) func() ([]*V, []error)

	// Prime the cache with the provided key and value. If the key already exists, no change is made
	// and false is returned.
	// (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)
	Prime(key K, value *V) bool

	// Clear the value at a key from the cache if it exists
	Clear(key K)
}

DataLoader batches and caches requests

func NewDataLoader

func NewDataLoader[K comparable, V any](fetchFn func(keys []K) ([]*V, []error), waitDuration time.Duration, maxBatch int) DataLoader[K, V]

NewDataLoader creates a new data loader given a fetch, wait and maxBatch

Jump to

Keyboard shortcuts

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