cache

package
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNegativeReferenceCount = errors.New("internal error: negative reference count")

Functions

func NewCacheWithDisposal added in v0.21.3

func NewCacheWithDisposal(p ParamsWithDisposal) *shardedCacheWithDisposal

Types

type Cache

type Cache interface {
	GetOrSet(k interface{}, setFn SetFn) (v interface{}, err error)
}

type CacheWithDisposal added in v0.21.3

type CacheWithDisposal interface {
	Name() string
	GetOrSet(k interface{}, setFn SetFn) (v interface{}, disposer Derefer, err error)
}

CacheWithDisposal is a cache that calls a disposal callback when an entry has been evicted and is no longer in use. Because of the structure of Go, it uses release callbacks and is not a Cache.

type ChanOnlyOne added in v0.21.2

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

func NewChanOnlyOne added in v0.21.2

func NewChanOnlyOne() *ChanOnlyOne

func (*ChanOnlyOne) Compute added in v0.21.2

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

type Derefer added in v0.21.3

type Derefer func() error

Derefer is the type of a function that returns an object to the cache, possibly causing its eviction.

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)

type JitterFn

type JitterFn func() time.Duration

func NewJitterFn

func NewJitterFn(jitter time.Duration) JitterFn

type OnlyOne added in v0.21.2

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 ParamsWithDisposal added in v0.21.3

type ParamsWithDisposal struct {
	Name   string
	Logger logging.Logger
	Size   int
	Shards int
	// OnDispose disposes of an entry.  It is called when the last reference to an entry
	// is released.  If it fails not much can be done.
	OnDispose func(value interface{}) error
}

type SetFn

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

type SingleThreadedCacheWithDisposal added in v0.21.3

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

SingleThreadedCacheWithDisposal is a CacheWithDisposal that uses a single critical section to prevent concurrent access to the cache and to reference counts on values.

func NewSingleThreadedCacheWithDisposal added in v0.21.3

func NewSingleThreadedCacheWithDisposal(p ParamsWithDisposal) *SingleThreadedCacheWithDisposal

func (*SingleThreadedCacheWithDisposal) GetOrSet added in v0.21.3

func (c *SingleThreadedCacheWithDisposal) GetOrSet(k interface{}, setFn SetFn) (interface{}, Derefer, error)

func (*SingleThreadedCacheWithDisposal) Name added in v0.21.3

Jump to

Keyboard shortcuts

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