loader

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 5 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 Loader

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

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

func New

func New(lf LoaderFunc, ttl time.Duration) *Loader

New initializes the loader

func (*Loader) Contains

func (ld *Loader) Contains(ctx context.Context, key string) bool

func (*Loader) Errors

func (ld *Loader) Errors() int64

func (*Loader) Hits

func (ld *Loader) Hits() int64

func (*Loader) Load

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

Load returns either a cached resource or calls the loader function to retrieve the requested resource

func (*Loader) Misses

func (ld *Loader) Misses() int64

func (*Loader) Ratio

func (ld *Loader) Ratio() float64

func (*Loader) Remove

func (ld *Loader) Remove(ctx context.Context, key string)

Remove removes a resource from the cache if it is there. The function does nothing otherwise.

func (*Loader) Stats

func (ld *Loader) Stats() string

func (*Loader) Update

func (ld *Loader) Update(ctx context.Context, key string, value interface{}) error

Update replaces a resource in the cache with a different one without loading it. It also resets the TTL.

type LoaderFunc

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

LoaderFunc abstracts the process of loading a resource

Jump to

Keyboard shortcuts

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