slice

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UserSliceLoader

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

UserSliceLoader batches and caches requests

func NewLoader

func NewLoader() *UserSliceLoader

func NewUserSliceLoader

func NewUserSliceLoader(config UserSliceLoaderConfig) *UserSliceLoader

NewUserSliceLoader creates a new UserSliceLoader given a fetch, wait, and maxBatch

func (*UserSliceLoader) Clear

func (l *UserSliceLoader) Clear(key string)

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

func (*UserSliceLoader) Load

func (l *UserSliceLoader) Load(key string) ([]example.User, error)

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

func (*UserSliceLoader) LoadAll

func (l *UserSliceLoader) LoadAll(keys []string) ([][]example.User, []error)

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

func (*UserSliceLoader) LoadAllThunk added in v0.4.0

func (l *UserSliceLoader) LoadAllThunk(keys []string) func() ([][]example.User, []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.

func (*UserSliceLoader) LoadThunk

func (l *UserSliceLoader) LoadThunk(key string) func() ([]example.User, 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.

func (*UserSliceLoader) Prime

func (l *UserSliceLoader) Prime(key string, value []example.User) 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 UserSliceLoaderCache added in v0.4.0

type UserSliceLoaderCache interface {
	Get(key string) ([]example.User, bool)
	Set(key string, value []example.User)
	ClearKey(key string)
}

UserSliceLoaderCache can be used to cache results. A default map based implementation is used by default.

type UserSliceLoaderConfig

type UserSliceLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []string) ([][]example.User, []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

	// Cache is the datastructure used to cache fetched data
	Cache UserSliceLoaderCache
}

UserSliceLoaderConfig captures the config to create a new UserSliceLoader

type UserSliceLoaderGoCache added in v0.4.0

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

func NewUserSliceLoaderGoCache added in v0.4.0

func NewUserSliceLoaderGoCache(conf UserSliceLoaderGoCacheConfig) *UserSliceLoaderGoCache

func (*UserSliceLoaderGoCache) ClearKey added in v0.4.0

func (c *UserSliceLoaderGoCache) ClearKey(key string)

func (*UserSliceLoaderGoCache) Get added in v0.4.0

func (c *UserSliceLoaderGoCache) Get(key string) ([]example.User, bool)

func (*UserSliceLoaderGoCache) Set added in v0.4.0

func (c *UserSliceLoaderGoCache) Set(key string, value []example.User)

type UserSliceLoaderGoCacheConfig added in v0.4.0

type UserSliceLoaderGoCacheConfig struct {
	DefaultExpiration time.Duration
	CleanupInterval   time.Duration
}

type UserSliceLoaderMapCache added in v0.4.0

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

func NewUserSliceLoaderMapCache added in v0.4.0

func NewUserSliceLoaderMapCache() *UserSliceLoaderMapCache

func (*UserSliceLoaderMapCache) ClearKey added in v0.4.0

func (c *UserSliceLoaderMapCache) ClearKey(key string)

func (*UserSliceLoaderMapCache) Get added in v0.4.0

func (c *UserSliceLoaderMapCache) Get(key string) ([]example.User, bool)

func (*UserSliceLoaderMapCache) Set added in v0.4.0

func (c *UserSliceLoaderMapCache) Set(key string, value []example.User)

Jump to

Keyboard shortcuts

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