Documentation ¶
Index ¶
- Constants
- type Cache
- func (c *Cache[T]) Clear(ctx context.Context) error
- func (c *Cache[T]) Delete(ctx context.Context, key any) error
- func (c *Cache[T]) Get(ctx context.Context, key any) (T, error)
- func (c *Cache[T]) GetCodec() codec.CodecInterface
- func (c *Cache[T]) GetType() string
- func (c *Cache[T]) GetWithTTL(ctx context.Context, key any) (T, time.Duration, error)
- func (c *Cache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
- func (c *Cache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error
- type CacheInterface
- type CacheKeyGenerator
- type ChainCache
- func (c *ChainCache[T]) Clear(ctx context.Context) error
- func (c *ChainCache[T]) Delete(ctx context.Context, key any) error
- func (c *ChainCache[T]) Get(ctx context.Context, key any) (T, error)
- func (c *ChainCache[T]) GetCaches() []SetterCacheInterface[T]
- func (c *ChainCache[T]) GetType() string
- func (c *ChainCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
- func (c *ChainCache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error
- type LoadFunction
- type LoadableCache
- func (c *LoadableCache[T]) Clear(ctx context.Context) error
- func (c *LoadableCache[T]) Close() error
- func (c *LoadableCache[T]) Delete(ctx context.Context, key any) error
- func (c *LoadableCache[T]) Get(ctx context.Context, key any) (T, error)
- func (c *LoadableCache[T]) GetType() string
- func (c *LoadableCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
- func (c *LoadableCache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error
- type MetricCache
- func (c *MetricCache[T]) Clear(ctx context.Context) error
- func (c *MetricCache[T]) Delete(ctx context.Context, key any) error
- func (c *MetricCache[T]) Get(ctx context.Context, key any) (T, error)
- func (c *MetricCache[T]) GetType() string
- func (c *MetricCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
- func (c *MetricCache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error
- type SetterCacheInterface
Constants ¶
const (
// CacheType represents the cache type as a string value
CacheType = "cache"
)
const (
// ChainType represents the chain cache type as a string value
ChainType = "chain"
)
const (
// LoadableType represents the loadable cache type as a string value
LoadableType = "loadable"
)
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[T any] struct { // contains filtered or unexported fields }
Cache represents the configuration needed by a cache
func (*Cache[T]) GetCodec ¶
func (c *Cache[T]) GetCodec() codec.CodecInterface
GetCodec returns the current codec
func (*Cache[T]) GetWithTTL ¶
GetWithTTL returns the object stored in cache and its corresponding TTL
func (*Cache[T]) Invalidate ¶
Invalidate invalidates cache item from given options
type CacheInterface ¶
type CacheInterface[T any] interface { Get(ctx context.Context, key any) (T, error) Set(ctx context.Context, key any, object T, options ...store.Option) error Delete(ctx context.Context, key any) error Invalidate(ctx context.Context, options ...store.InvalidateOption) error Clear(ctx context.Context) error GetType() string }
CacheInterface represents the interface for all caches (aggregates, metric, memory, redis, ...)
type CacheKeyGenerator ¶
type CacheKeyGenerator interface {
GetCacheKey() string
}
type ChainCache ¶
type ChainCache[T any] struct { // contains filtered or unexported fields }
ChainCache represents the configuration needed by a cache aggregator
func NewChain ¶
func NewChain[T any](caches ...SetterCacheInterface[T]) *ChainCache[T]
NewChain instantiates a new cache aggregator
func (*ChainCache[T]) Clear ¶
func (c *ChainCache[T]) Clear(ctx context.Context) error
Clear resets all cache data
func (*ChainCache[T]) Delete ¶
func (c *ChainCache[T]) Delete(ctx context.Context, key any) error
Delete removes a value from all available caches
func (*ChainCache[T]) Get ¶
func (c *ChainCache[T]) Get(ctx context.Context, key any) (T, error)
Get returns the object stored in cache if it exists
func (*ChainCache[T]) GetCaches ¶
func (c *ChainCache[T]) GetCaches() []SetterCacheInterface[T]
GetCaches returns all Chained caches
func (*ChainCache[T]) GetType ¶
func (c *ChainCache[T]) GetType() string
GetType returns the cache type
func (*ChainCache[T]) Invalidate ¶
func (c *ChainCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
Invalidate invalidates cache item from given options
type LoadableCache ¶
type LoadableCache[T any] struct { // contains filtered or unexported fields }
LoadableCache represents a cache that uses a function to load data
func NewLoadable ¶
func NewLoadable[T any](loadFunc LoadFunction[T], cache CacheInterface[T]) *LoadableCache[T]
NewLoadable instanciates a new cache that uses a function to load data
func (*LoadableCache[T]) Clear ¶
func (c *LoadableCache[T]) Clear(ctx context.Context) error
Clear resets all cache data
func (*LoadableCache[T]) Close ¶
func (c *LoadableCache[T]) Close() error
func (*LoadableCache[T]) Delete ¶
func (c *LoadableCache[T]) Delete(ctx context.Context, key any) error
Delete removes a value from cache
func (*LoadableCache[T]) Get ¶
func (c *LoadableCache[T]) Get(ctx context.Context, key any) (T, error)
Get returns the object stored in cache if it exists
func (*LoadableCache[T]) GetType ¶
func (c *LoadableCache[T]) GetType() string
GetType returns the cache type
func (*LoadableCache[T]) Invalidate ¶
func (c *LoadableCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
Invalidate invalidates cache item from given options
type MetricCache ¶
type MetricCache[T any] struct { // contains filtered or unexported fields }
MetricCache is the struct that specifies metrics available for different caches
func NewMetric ¶
func NewMetric[T any](metrics metrics.MetricsInterface, cache CacheInterface[T]) *MetricCache[T]
NewMetric creates a new cache with metrics and a given cache storage
func (*MetricCache[T]) Clear ¶
func (c *MetricCache[T]) Clear(ctx context.Context) error
Clear resets all cache data
func (*MetricCache[T]) Delete ¶
func (c *MetricCache[T]) Delete(ctx context.Context, key any) error
Delete removes a value from the cache
func (*MetricCache[T]) Get ¶
func (c *MetricCache[T]) Get(ctx context.Context, key any) (T, error)
Get obtains a value from cache and also records metrics
func (*MetricCache[T]) GetType ¶
func (c *MetricCache[T]) GetType() string
GetType returns the cache type
func (*MetricCache[T]) Invalidate ¶
func (c *MetricCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
Invalidate invalidates cache item from given options
type SetterCacheInterface ¶
type SetterCacheInterface[T any] interface { // CacheInterface[T] TODO: Waiting for gomock to support nested interfaces with generics. Get(ctx context.Context, key any) (T, error) Set(ctx context.Context, key any, object T, options ...store.Option) error Delete(ctx context.Context, key any) error Invalidate(ctx context.Context, options ...store.InvalidateOption) error Clear(ctx context.Context) error GetType() string GetWithTTL(ctx context.Context, key any) (T, time.Duration, error) GetCodec() codec.CodecInterface }
SetterCacheInterface represents the interface for caches that allows storage (for instance: memory, redis, ...)