cache

package
v0.0.0-...-432d548 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound indicates the cache not found.
	ErrKeyNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type LoaderFunc

type LoaderFunc func(key interface{}) (interface{}, error)

LoaderFunc load values for a cache key.

type PipeCache

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

PipeCache limits cache loader (load values from remote services) in a pipe, which means limit the concurrence. NOTE: The refactor version here only allows 1 concurrent to load for simple implementation reason.

func NewPipeCache

func NewPipeCache(store Store) *PipeCache

NewPipeCache create a new piped cache.

func (*PipeCache) Fetch

func (pc *PipeCache) Fetch(key interface{}, expiration time.Duration, loader LoaderFunc) (interface{}, error)

Fetch get the cache value, if the value not found, call loader to load. This function limits the cocurrent loader count.

type Store

type Store interface {
	Get(key interface{}) (interface{}, error)
	SetWithExpire(key, value interface{}, expiration time.Duration) error
}

Store represents a cache implementation which stores key value.

Jump to

Keyboard shortcuts

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