func (l *UserSliceLoader) Prime(key int, value []*entity.User) bool {
	l.mu.Lock()
	var found bool
	if _, found = l.cache[key]; !found {
		cpy := make([]*entity.User, len(value))
		copy(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 gqldataloaders
import (
	"sync"
	"time"
	"go-webapp-example/internal/pkg/entity"
)
type UserSliceLoaderConfig struct {
	Fetch func(keys []int) ([][]*entity.User, []error)
	Wait time.Duration
	MaxBatch int
}
func NewUserSliceLoader(config UserSliceLoaderConfig) *UserSliceLoader {
	return &UserSliceLoader{
		fetch:    config.Fetch,
		wait:     config.Wait,
		maxBatch: config.MaxBatch,
	}
}
type UserSliceLoader struct {
	fetch func(keys []int) ([][]*entity.User, []error)
	wait time.Duration
	maxBatch int
	cache map[int][]*entity.User
	batch *userSliceLoaderBatch
	mu sync.Mutex
}
type userSliceLoaderBatch struct {
	keys    []int
	data    [][]*entity.User
	error   []error
	closing bool
	done    chan struct{}
}
func (l *UserSliceLoader) Load(key int) ([]*entity.User, error) {
	return l.LoadThunk(key)()
}
func (l *UserSliceLoader) LoadThunk(key int) func() ([]*entity.User, error) {
	l.mu.Lock()
	if it, ok := l.cache[key]; ok {
		l.mu.Unlock()
		return func() ([]*entity.User, error) {
			return it, nil
		}
	}
	if l.batch == nil {
		l.batch = &userSliceLoaderBatch{done: make(chan struct{})}
	}
	batch := l.batch
	pos := batch.keyIndex(l, key)
	l.mu.Unlock()
	return func() ([]*entity.User, error) {
		<-batch.done
		var data []*entity.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 *UserSliceLoader) LoadAll(keys []int) ([][]*entity.User, []error) {
	results := make([]func() ([]*entity.User, error), len(keys))
	for i, key := range keys {
		results[i] = l.LoadThunk(key)
	}
	users := make([][]*entity.User, len(keys))
	errors := make([]error, len(keys))
	for i, thunk := range results {
		users[i], errors[i] = thunk()
	}
	return users, errors
}
func (l *UserSliceLoader) LoadAllThunk(keys []int) func() ([][]*entity.User, []error) {
	results := make([]func() ([]*entity.User, error), len(keys))
	for i, key := range keys {
		results[i] = l.LoadThunk(key)
	}
	return func() ([][]*entity.User, []error) {
		users := make([][]*entity.User, len(keys))
		errors := make([]error, len(keys))
		for i, thunk := range results {
			users[i], errors[i] = thunk()
		}
		return users, errors
	}
}