cache

package
v5.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expired

type Expired struct {
	Key   string
	When  time.Time
	Value interface{}
}

Expired is a special type of error indicating that a key is no longer valid (value is still attached in the error)

func (*Expired) Error

func (e *Expired) Error() string

type LocalCache

type LocalCache interface {
	Get(key string) (interface{}, error)
	Set(key string, value interface{}) error
}

LocalCache is an in-memory TTL & LRU cache

type LocalCacheImpl

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

LocalCacheImpl implements the LocalCache interface

func NewLocalCache

func NewLocalCache(maxSize int, ttl time.Duration) (*LocalCacheImpl, error)

NewLocalCache returns a new LocalCache instance of the specified size and TTL

func (*LocalCacheImpl) Get

func (c *LocalCacheImpl) Get(key string) (interface{}, error)

Get retrieves an item if exist, nil + an error otherwise

func (*LocalCacheImpl) Set

func (c *LocalCacheImpl) Set(key string, value interface{}) error

Set adds a new item. Since the cache being full results in removing the LRU element, this method never fails.

type MLCLayer added in v5.0.3

type MLCLayer interface {
	Get(ctx context.Context, key string) (interface{}, error)
	Set(ctx context.Context, key string, value interface{}) error
}

MLCLayer is the interface that should be implemented for all caching structs to be used with this piece of code.

type Miss

type Miss struct {
	Where string
	Key   string
}

Miss is a special type of error indicating that a key was not found

func (*Miss) Error

func (c *Miss) Error() string

type MultiLevelCache

type MultiLevelCache interface {
	Get(ctx context.Context, key string) (interface{}, error)
}

MultiLevelCache bundles a list of ordered cache layers (upper -> lower)

type MultiLevelCacheImpl

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

MultiLevelCacheImpl implements the MultiLevelCache interface

func NewMultiLevel

func NewMultiLevel(layers []MLCLayer, logger logging.LoggerInterface) (*MultiLevelCacheImpl, error)

NewMultiLevel creates and returns a new MultiLevelCache instance

func (*MultiLevelCacheImpl) Get

func (c *MultiLevelCacheImpl) Get(ctx context.Context, key string) (interface{}, error)

Get returns the value of the requested key (if found) and populates upper levels with it

Jump to

Keyboard shortcuts

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