cache

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: MIT Imports: 7 Imported by: 19

Documentation

Index

Constants

View Source
const (
	// CacheType represents the cache type as a string value
	CacheType = "cache"
)
View Source
const (
	// ChainType represents the chain cache type as a string value
	ChainType = "chain"
)
View Source
const (
	// LoadableType represents the loadable cache type as a string value
	LoadableType = "loadable"
)
View Source
const (
	// MetricType represents the metric cache type as a string value
	MetricType = "metric"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache represents the configuration needed by a cache

func New

func New(store store.StoreInterface) *Cache

New instantiates a new cache entry

func (*Cache) Clear added in v1.0.0

func (c *Cache) Clear() error

Clear resets all cache data

func (*Cache) Delete added in v0.2.0

func (c *Cache) Delete(key interface{}) error

Delete removes the cache item using the given key

func (*Cache) Get

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

Get returns the object stored in cache if it exists

func (*Cache) GetCodec

func (c *Cache) GetCodec() codec.CodecInterface

GetCodec returns the current codec

func (*Cache) GetType

func (c *Cache) GetType() string

GetType returns the cache type

func (*Cache) GetWithTTL added in v1.1.0

func (c *Cache) GetWithTTL(key interface{}) (interface{}, time.Duration, error)

GetWithTTL returns the object stored in cache and its corresponding TTL

func (*Cache) Invalidate added in v0.2.0

func (c *Cache) Invalidate(options store.InvalidateOptions) error

Invalidate invalidates cache item from given options

func (*Cache) Set

func (c *Cache) Set(key, object interface{}, options *store.Options) error

Set populates the cache item using the given key

type CacheInterface

type CacheInterface interface {
	Get(key interface{}) (interface{}, error)
	Set(key, object interface{}, options *store.Options) error
	Delete(key interface{}) error
	Invalidate(options store.InvalidateOptions) error
	Clear() error
	GetType() string
}

CacheInterface represents the interface for all caches (aggregates, metric, memory, redis, ...)

type ChainCache

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

ChainCache represents the configuration needed by a cache aggregator

func NewChain

func NewChain(caches ...SetterCacheInterface) *ChainCache

NewChain instantiates a new cache aggregator

func (*ChainCache) Clear added in v1.0.0

func (c *ChainCache) Clear() error

Clear resets all cache data

func (*ChainCache) Delete added in v0.2.0

func (c *ChainCache) Delete(key interface{}) error

Delete removes a value from all available caches

func (*ChainCache) Get

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

Get returns the object stored in cache if it exists

func (*ChainCache) GetCaches

func (c *ChainCache) GetCaches() []SetterCacheInterface

GetCaches returns all Chained caches

func (*ChainCache) GetType

func (c *ChainCache) GetType() string

GetType returns the cache type

func (*ChainCache) Invalidate added in v0.2.0

func (c *ChainCache) Invalidate(options store.InvalidateOptions) error

Invalidate invalidates cache item from given options

func (*ChainCache) Set

func (c *ChainCache) Set(key, object interface{}, options *store.Options) error

Set sets a value in available caches

type LoadableCache

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

LoadableCache represents a cache that uses a function to load data

func NewLoadable

func NewLoadable(loadFunc loadFunction, cache CacheInterface) *LoadableCache

NewLoadable instanciates a new cache that uses a function to load data

func (*LoadableCache) Clear added in v1.0.0

func (c *LoadableCache) Clear() error

Clear resets all cache data

func (*LoadableCache) Delete added in v0.2.0

func (c *LoadableCache) Delete(key interface{}) error

Delete removes a value from cache

func (*LoadableCache) Get

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

Get returns the object stored in cache if it exists

func (*LoadableCache) GetType

func (c *LoadableCache) GetType() string

GetType returns the cache type

func (*LoadableCache) Invalidate added in v0.2.0

func (c *LoadableCache) Invalidate(options store.InvalidateOptions) error

Invalidate invalidates cache item from given options

func (*LoadableCache) Set

func (c *LoadableCache) Set(key, object interface{}, options *store.Options) error

Set sets a value in available caches

type MetricCache

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

MetricCache is the struct that specifies metrics available for different caches

func NewMetric

func NewMetric(metrics metrics.MetricsInterface, cache CacheInterface) *MetricCache

NewMetric creates a new cache with metrics and a given cache storage

func (*MetricCache) Clear added in v1.0.0

func (c *MetricCache) Clear() error

Clear resets all cache data

func (*MetricCache) Delete added in v0.2.0

func (c *MetricCache) Delete(key interface{}) error

Delete removes a value from the cache

func (*MetricCache) Get

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

Get obtains a value from cache and also records metrics

func (*MetricCache) GetType

func (c *MetricCache) GetType() string

GetType returns the cache type

func (*MetricCache) Invalidate added in v0.2.0

func (c *MetricCache) Invalidate(options store.InvalidateOptions) error

Invalidate invalidates cache item from given options

func (*MetricCache) Set

func (c *MetricCache) Set(key, object interface{}, options *store.Options) error

Set sets a value from the cache

type SetterCacheInterface

type SetterCacheInterface interface {
	CacheInterface
	GetWithTTL(key interface{}) (interface{}, time.Duration, error)

	GetCodec() codec.CodecInterface
}

SetterCacheInterface represents the interface for caches that allows storage (for instance: memory, redis, ...)

Jump to

Keyboard shortcuts

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