loaders

package
v0.0.0-...-09d31aa Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: ISC Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelLoader

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

ChannelLoader batches and caches requests

func ChannelLoaderFromRepository

func ChannelLoaderFromRepository(repo repositories.ChannelRepository) *ChannelLoader

ChannelLoaderFromRepository creates a new CharacterLoader

func NewChannelLoader

func NewChannelLoader(config ChannelLoaderConfig) *ChannelLoader

NewChannelLoader creates a new ChannelLoader given a fetch, wait, and maxBatch

func (*ChannelLoader) Clear

func (l *ChannelLoader) Clear(key string)

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

func (*ChannelLoader) Load

func (l *ChannelLoader) Load(key string) (*models.Channel, error)

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

func (*ChannelLoader) LoadAll

func (l *ChannelLoader) LoadAll(keys []string) ([]*models.Channel, []error)

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

func (*ChannelLoader) LoadAllThunk

func (l *ChannelLoader) LoadAllThunk(keys []string) func() ([]*models.Channel, []error)

LoadAllThunk returns a function that when called will block waiting for a Channels. 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 (*ChannelLoader) LoadThunk

func (l *ChannelLoader) LoadThunk(key string) func() (*models.Channel, error)

LoadThunk returns a function that when called will block waiting for a Channel. 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 (*ChannelLoader) Prime

func (l *ChannelLoader) Prime(key string, value *models.Channel) 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 ChannelLoaderConfig

type ChannelLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []string) ([]*models.Channel, []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
}

ChannelLoaderConfig captures the config to create a new ChannelLoader

type CharacterLoader

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

CharacterLoader batches and caches requests

func CharacterLoaderFromRepository

func CharacterLoaderFromRepository(repo repositories.CharacterRepository) *CharacterLoader

CharacterLoaderFromRepository creates a new CharacterLoader

func NewCharacterLoader

func NewCharacterLoader(config CharacterLoaderConfig) *CharacterLoader

NewCharacterLoader creates a new CharacterLoader given a fetch, wait, and maxBatch

func (*CharacterLoader) Clear

func (l *CharacterLoader) Clear(key string)

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

func (*CharacterLoader) Load

func (l *CharacterLoader) Load(key string) (*models.Character, error)

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

func (*CharacterLoader) LoadAll

func (l *CharacterLoader) LoadAll(keys []string) ([]*models.Character, []error)

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

func (*CharacterLoader) LoadAllThunk

func (l *CharacterLoader) LoadAllThunk(keys []string) func() ([]*models.Character, []error)

LoadAllThunk returns a function that when called will block waiting for a Characters. 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 (*CharacterLoader) LoadThunk

func (l *CharacterLoader) LoadThunk(key string) func() (*models.Character, error)

LoadThunk returns a function that when called will block waiting for a Character. 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 (*CharacterLoader) Prime

func (l *CharacterLoader) Prime(key string, value *models.Character) 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 CharacterLoaderConfig

type CharacterLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []string) ([]*models.Character, []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
}

CharacterLoaderConfig captures the config to create a new CharacterLoader

Jump to

Keyboard shortcuts

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