Documentation
¶
Index ¶
- type User
- type UserLoader
- func (l *UserLoader) Clear(key string)
- func (l *UserLoader) Load(key string) (*User, error)
- func (l *UserLoader) LoadAll(keys []string) ([]*User, []error)
- func (l *UserLoader) LoadAllThunk(keys []string) func() ([]*User, []error)
- func (l *UserLoader) LoadThunk(key string) func() (*User, error)
- func (l *UserLoader) Prime(key string, value *User) bool
- type UserLoaderCache
- type UserLoaderConfig
- type UserLoaderGoCache
- type UserLoaderGoCacheConfig
- type UserLoaderMapCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type UserLoader ¶
type UserLoader struct {
// contains filtered or unexported fields
}
UserLoader batches and caches requests
func NewLoader ¶
func NewLoader() *UserLoader
NewLoader will collect user requests for 2 milliseconds and send them as a single batch to the fetch func normally fetch would be a database call.
func NewUserLoader ¶
func NewUserLoader(config UserLoaderConfig) *UserLoader
NewUserLoader creates a new UserLoader given a fetch, wait, and maxBatch
func (*UserLoader) Clear ¶
func (l *UserLoader) Clear(key string)
Clear the value at key from the cache, if it exists
func (*UserLoader) Load ¶
func (l *UserLoader) Load(key string) (*User, error)
Load a User by key, batching and caching will be applied automatically
func (*UserLoader) LoadAll ¶
func (l *UserLoader) LoadAll(keys []string) ([]*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 (*UserLoader) LoadAllThunk ¶ added in v0.4.0
func (l *UserLoader) LoadAllThunk(keys []string) func() ([]*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 (*UserLoader) LoadThunk ¶
func (l *UserLoader) LoadThunk(key string) func() (*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.
type UserLoaderCache ¶ added in v0.4.0
type UserLoaderCache interface {
Get(key string) (*User, bool)
Set(key string, value *User)
ClearKey(key string)
}
UserLoaderCache can be used to cache results. A default map based implementation is used by default.
type UserLoaderConfig ¶
type UserLoaderConfig struct {
// Fetch is a method that provides the data for the loader
Fetch func(keys []string) ([]*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 UserLoaderCache
}
UserLoaderConfig captures the config to create a new UserLoader
type UserLoaderGoCache ¶ added in v0.4.0
type UserLoaderGoCache struct {
// contains filtered or unexported fields
}
func NewUserLoaderGoCache ¶ added in v0.4.0
func NewUserLoaderGoCache(conf UserLoaderGoCacheConfig) *UserLoaderGoCache
func (*UserLoaderGoCache) ClearKey ¶ added in v0.4.0
func (c *UserLoaderGoCache) ClearKey(key string)
func (*UserLoaderGoCache) Get ¶ added in v0.4.0
func (c *UserLoaderGoCache) Get(key string) (*User, bool)
func (*UserLoaderGoCache) Set ¶ added in v0.4.0
func (c *UserLoaderGoCache) Set(key string, value *User)
type UserLoaderGoCacheConfig ¶ added in v0.4.0
type UserLoaderMapCache ¶ added in v0.4.0
type UserLoaderMapCache struct {
// contains filtered or unexported fields
}
func NewUserLoaderMapCache ¶ added in v0.4.0
func NewUserLoaderMapCache() *UserLoaderMapCache
func (*UserLoaderMapCache) ClearKey ¶ added in v0.4.0
func (c *UserLoaderMapCache) ClearKey(key string)
func (*UserLoaderMapCache) Get ¶ added in v0.4.0
func (c *UserLoaderMapCache) Get(key string) (*User, bool)
func (*UserLoaderMapCache) Set ¶ added in v0.4.0
func (c *UserLoaderMapCache) Set(key string, value *User)