cache

package
v0.0.0-...-ec09dfe Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: GPL-3.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCacheUnit

func NewCacheUnit(data interface{}, isValid func(u *unit) bool) *unit

NewCacheUnit creates a new cacheable chunk of data. Optionally a function `isValid` can be provided to check if a `*unit` is valid. If this function fails the cache will purge the key.

Types

type CacheImpl

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

CacheImpl implements patrickmn's `go-cache`.

func (*CacheImpl) Clear

func (c *CacheImpl) Clear()

func (*CacheImpl) Delete

func (c *CacheImpl) Delete(key string) error

func (*CacheImpl) Get

func (c *CacheImpl) Get(key string) (interface{}, bool)

func (*CacheImpl) GetDefault

func (c *CacheImpl) GetDefault(key string, d interface{}) interface{}

func (*CacheImpl) Put

func (c *CacheImpl) Put(key string, unit *unit) error

func (*CacheImpl) PutExpiry

func (c *CacheImpl) PutExpiry(key string, unit *unit, expiry time.Time) error

func (*CacheImpl) Set

func (c *CacheImpl) Set(key string, unit *unit) error

func (*CacheImpl) SetExpiry

func (c *CacheImpl) SetExpiry(key string, unit *unit, expiry time.Time) error

type Cacher

type Cacher interface {
	// Put sets, if not present, the key to the `*cache.Unit`, with default
	// expiry. May return an error depending on impl.
	Put(key string, unit *unit) error
	// PutExpiry sets, if not present, the key to the `*cache.Unit`, with
	// given expiry. May return an error depending on impl.
	PutExpiry(key string, unit *unit, expiry time.Time) error
	// Set sets, the key to the `*cache.Unit`, present or not, with default
	// expiry. May return an error depending on impl.
	Set(key string, unit *unit) error
	// SetExpiry sets, the key to the `*cache.Unit`, present or not, with
	// given expiry. May return an error depending on impl.
	SetExpiry(key string, unit *unit, expiry time.Time) error
	// Get returns the key's unit's value if valid. Checks the `isValid`
	// function & expiry times. Bool indicates if present (& valid).
	Get(key string) (interface{}, bool)
	// GetDefault returns the key's unit's value if valid. Checks the `isValid`
	// function & expiry times. If not present (or valid) `d` is returned.
	GetDefault(key string, d interface{}) interface{}
	// Delete will remove the key from the cache. May return an error depending
	// on impl.
	Delete(key string) error
	Clear()
}

Cacher represents all cache implementations, barebones interoperable functions, for any implementation that may be used down the line.

func NewCache

func NewCache(defaultTtl *time.Duration, defaultClean *time.Duration) Cacher

Jump to

Keyboard shortcuts

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