dataloader

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dataloader

type Dataloader[K comparable, T any] struct {
	// contains filtered or unexported fields
}

Dataloader batches and caches requests

func NewDataloader

func NewDataloader[K comparable, T any](

	fetch func(keys []K) ([]T, []error),

	wait time.Duration,

	maxBatch int,
) *Dataloader[K, T]

NewDataloader creates a new Dataloader given a fetch, wait, and maxBatch

func (*Dataloader[K, T]) Clear

func (l *Dataloader[K, T]) Clear(key K)

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

func (*Dataloader[K, T]) ClearAll

func (l *Dataloader[K, T]) ClearAll()

ClearAll values from the cache

func (*Dataloader[K, T]) Load

func (l *Dataloader[K, T]) Load(key K) (T, error)

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

func (*Dataloader[K, T]) LoadAll

func (l *Dataloader[K, T]) LoadAll(keys []K) ([]T, []error)

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

func (*Dataloader[K, T]) LoadAllThunk

func (l *Dataloader[K, T]) LoadAllThunk(keys []K) func() ([]T, []error)

LoadAllThunk returns a function that when called will block waiting for a T. 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 (*Dataloader[K, T]) LoadThunk

func (l *Dataloader[K, T]) LoadThunk(key K) func() (T, error)

LoadThunk returns a function that when called will block waiting for a T. 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 (*Dataloader[K, T]) Prime

func (l *Dataloader[K, T]) Prime(key K, value T) 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).)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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