Documentation
¶
Index ¶
- func DataloaderMiddleware(nr registry.Registry) func(http.Handler) http.Handler
- type Loaders
- type Retriever
- type StrainLoader
- func (l *StrainLoader) Clear(key string)
- func (l *StrainLoader) Load(key string) (*models.Strain, error)
- func (l *StrainLoader) LoadAll(keys []string) ([]*models.Strain, []error)
- func (l *StrainLoader) LoadAllThunk(keys []string) func() ([]*models.Strain, []error)
- func (l *StrainLoader) LoadThunk(key string) func() (*models.Strain, error)
- func (l *StrainLoader) Prime(key string, value *models.Strain) bool
- type StrainLoaderConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Loaders ¶
type Loaders struct {
StrainByID *StrainLoader
}
type Retriever ¶
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