dataloader

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTTL is the default TTL used if nothing else is specified
	DefaultTTL = time.Minute * 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FetchFunc

type FetchFunc func(context.Context, string) (interface{}, error)

FetchFunc abstracts the process of loading a resource

type Loader

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

Loader holds cached resources. The cache is a simple in-memory cache with TTL.

func NewLoader

func NewLoader(f FetchFunc, ttl time.Duration) *Loader

NewLoader initializes the loader

func (*Loader) Load

func (l *Loader) Load(ctx context.Context, key string) (interface{}, error)

Load returns either a cached instance or calls the fetch function to retriece the requested instance

Jump to

Keyboard shortcuts

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