dataloader

package
v0.0.0-...-a9002f1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataloaderMiddleware

func DataloaderMiddleware(nr registry.Registry) func(http.Handler) http.Handler

DataloaderMiddleware stores Loaders as a request-scoped context value.

Types

type Loaders

type Loaders struct {
	StrainByID *StrainLoader
}

type Retriever

type Retriever interface {
	Retrieve(context.Context) *Loaders
}

Retriever retrieves dataloaders from the request context.

func NewRetriever

func NewRetriever() Retriever

NewRetriever instantiates a new implementation of Retriever.

type StrainLoader

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

StrainLoader batches and caches requests

func NewStrainLoader

func NewStrainLoader(config StrainLoaderConfig) *StrainLoader

NewStrainLoader creates a new StrainLoader given a fetch, wait, and maxBatch

func (*StrainLoader) Clear

func (l *StrainLoader) Clear(key string)

Clear the value at key from the cache, if it exists

func (*StrainLoader) Load

func (l *StrainLoader) Load(key string) (*models.Strain, error)

Load a Strain by key, batching and caching will be applied automatically

func (*StrainLoader) LoadAll

func (l *StrainLoader) LoadAll(keys []string) ([]*models.Strain, []error)

LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured

func (*StrainLoader) LoadAllThunk

func (l *StrainLoader) LoadAllThunk(keys []string) func() ([]*models.Strain, []error)

LoadAllThunk returns a function that when called will block waiting for a Strains. 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.

func (*StrainLoader) LoadThunk

func (l *StrainLoader) LoadThunk(key string) func() (*models.Strain, error)

LoadThunk returns a function that when called will block waiting for a Strain. 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.

func (*StrainLoader) Prime

func (l *StrainLoader) Prime(key string, value *models.Strain) bool

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).)

type StrainLoaderConfig

type StrainLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []string) ([]*models.Strain, []error)

	// Wait is how long wait before sending a batch
	Wait time.Duration

	// MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit
	MaxBatch int
}

StrainLoaderConfig captures the config to create a new StrainLoader

Jump to

Keyboard shortcuts

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