func (l *UserLoader) Prime(key string, value *User) bool {
	l.mu.Lock()
	var found bool
	if _, found = l.cache[key]; !found {
		cpy := *value
		l.unsafeSet(key, &cpy)
	}
	l.mu.Unlock()
	return !found
}
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).)
package example
import (
	"sync"
	"time"
)
type UserLoaderConfig struct {
	Fetch func(keys []string) ([]*User, []error)
	Wait time.Duration
	MaxBatch int
}
func NewUserLoader(config UserLoaderConfig) *UserLoader {
	return &UserLoader{
		fetch:    config.Fetch,
		wait:     config.Wait,
		maxBatch: config.MaxBatch,
	}
}
type UserLoader struct {
	fetch func(keys []string) ([]*User, []error)
	wait time.Duration
	maxBatch int
	cache map[string]*User
	batch *userLoaderBatch
	mu sync.Mutex
}
type userLoaderBatch struct {
	keys    []string
	data    []*User
	error   []error
	closing bool
	done    chan struct{}
}
func (l *UserLoader) Load(key string) (*User, error) {
	return l.LoadThunk(key)()
}
func (l *UserLoader) LoadThunk(key string) func() (*User, error) {
	l.mu.Lock()
	if it, ok := l.cache[key]; ok {
		l.mu.Unlock()
		return func() (*User, error) {
			return it, nil
		}
	}
	if l.batch == nil {
		l.batch = &userLoaderBatch{done: make(chan struct{})}
	}
	batch := l.batch
	pos := batch.keyIndex(l, key)
	l.mu.Unlock()
	return func() (*User, error) {
		<-batch.done
		var data *User
		if pos < len(batch.data) {
			data = batch.data[pos]
		}
		var err error
		if len(batch.error) == 1 {
			err = batch.error[0]
		} else if batch.error != nil {
			err = batch.error[pos]
		}
		if err == nil {
			l.mu.Lock()
			l.unsafeSet(key, data)
			l.mu.Unlock()
		}
		return data, err
	}
}
func (l *UserLoader) LoadAll(keys []string) ([]*User, []error) {
	results := make([]func() (*User, error), len(keys))
	for i, key := range keys {
		results[i] = l.LoadThunk(key)
	}
	users := make([]*User, len(keys))
	errors := make([]error, len(keys))
	for i, thunk := range results {
		users[i], errors[i] = thunk()
	}
	return users, errors
}
func (l *UserLoader) LoadAllThunk(keys []string) func() ([]*User, []error) {
	results := make([]func() (*User, error), len(keys))
	for i, key := range keys {
		results[i] = l.LoadThunk(key)
	}
	return func() ([]*User, []error) {
		users := make([]*User, len(keys))
		errors := make([]error, len(keys))
		for i, thunk := range results {
			users[i], errors[i] = thunk()
		}
		return users, errors
	}
}