cache

package module
v0.0.0-...-b3c2e92 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	GetOrSet(k interface{}, setFn SetFn) (v interface{}, err error)
	GetOrSetWithExpiry(k interface{}, setFn SetFnWithExpiry) (v interface{}, err error)
}
var NoCache Cache = &noCache{}

type ChanOnlyOne

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

func NewChanOnlyOne

func NewChanOnlyOne() *ChanOnlyOne

func (*ChanOnlyOne) Compute

func (c *ChanOnlyOne) Compute(k interface{}, fn func() (interface{}, error)) (interface{}, error)

type GetSetCache

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

func NewCache

func NewCache(size int, expiry time.Duration, jitterFn JitterFn) *GetSetCache

func (*GetSetCache) GetOrSet

func (c *GetSetCache) GetOrSet(k interface{}, setFn SetFn) (v interface{}, err error)

func (*GetSetCache) GetOrSetWithExpiry

func (c *GetSetCache) GetOrSetWithExpiry(k interface{}, setFn SetFnWithExpiry) (v interface{}, err error)

type JitterFn

type JitterFn func() time.Duration

func NewJitterFn

func NewJitterFn(jitter time.Duration) JitterFn

type OnlyOne

type OnlyOne interface {
	// Compute returns the value of calling fn(), but only calls fn once concurrently for
	// each k.
	Compute(k interface{}, fn func() (interface{}, error)) (interface{}, error)
}

OnlyOne ensures only one concurrent evaluation of a keyed expression.

type SetFn

type SetFn func() (v interface{}, err error)

type SetFnWithExpiry

type SetFnWithExpiry func() (v interface{}, expiry time.Duration, err error)

SetWithExpiry is a function called to set a value in the cache. It returns the desired value and when to expire it from the cache. The cache default expiration value is used if it returns a zero expiration.

Jump to

Keyboard shortcuts

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