Documentation ¶
Index ¶
- Constants
- type Cache
- func (c *Cache) Clear(ctx context.Context) error
- func (c *Cache) Delete(ctx context.Context, key interface{}) error
- func (c *Cache) Get(ctx context.Context, key interface{}) (interface{}, error)
- func (c *Cache) GetCodec() codec.CodecInterface
- func (c *Cache) GetType() string
- func (c *Cache) GetWithTTL(ctx context.Context, key interface{}) (interface{}, time.Duration, error)
- func (c *Cache) Invalidate(ctx context.Context, options store.InvalidateOptions) error
- func (c *Cache) Set(ctx context.Context, key, object interface{}, options *store.Options) error
- type CacheInterface
- type CacheKeyGenerator
- type ChainCache
- func (c *ChainCache) Clear(ctx context.Context) error
- func (c *ChainCache) Delete(ctx context.Context, key interface{}) error
- func (c *ChainCache) Get(ctx context.Context, key interface{}) (interface{}, error)
- func (c *ChainCache) GetCaches() []SetterCacheInterface
- func (c *ChainCache) GetType() string
- func (c *ChainCache) Invalidate(ctx context.Context, options store.InvalidateOptions) error
- func (c *ChainCache) Set(ctx context.Context, key, object interface{}, options *store.Options) error
- type LoadableCache
- func (c *LoadableCache) Clear(ctx context.Context) error
- func (c *LoadableCache) Close() error
- func (c *LoadableCache) Delete(ctx context.Context, key interface{}) error
- func (c *LoadableCache) Get(ctx context.Context, key interface{}) (interface{}, error)
- func (c *LoadableCache) GetType() string
- func (c *LoadableCache) Invalidate(ctx context.Context, options store.InvalidateOptions) error
- func (c *LoadableCache) Set(ctx context.Context, key, object interface{}, options *store.Options) error
- type MetricCache
- func (c *MetricCache) Clear(ctx context.Context) error
- func (c *MetricCache) Delete(ctx context.Context, key interface{}) error
- func (c *MetricCache) Get(ctx context.Context, key interface{}) (interface{}, error)
- func (c *MetricCache) GetType() string
- func (c *MetricCache) Invalidate(ctx context.Context, options store.InvalidateOptions) error
- func (c *MetricCache) Set(ctx context.Context, key, object interface{}, options *store.Options) 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 struct {
// contains filtered or unexported fields
}
Cache represents the configuration needed by a cache
func (*Cache) GetCodec ¶
func (c *Cache) GetCodec() codec.CodecInterface
GetCodec returns the current codec
func (*Cache) GetWithTTL ¶
func (c *Cache) GetWithTTL(ctx context.Context, key interface{}) (interface{}, time.Duration, error)
GetWithTTL returns the object stored in cache and its corresponding TTL
func (*Cache) Invalidate ¶
Invalidate invalidates cache item from given options
type CacheInterface ¶
type CacheInterface interface { Get(ctx context.Context, key interface{}) (interface{}, error) Set(ctx context.Context, key, object interface{}, options *store.Options) error Delete(ctx context.Context, key interface{}) error Invalidate(ctx context.Context, options store.InvalidateOptions) error Clear(ctx context.Context) error GetType() string }
CacheInterface represents the interface for all caches (aggregates, metric, memory, redis, ...)
type CacheKeyGenerator ¶ added in v2.2.0
type CacheKeyGenerator interface {
GetCacheKey() string
}
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 ¶
func (c *ChainCache) Clear(ctx context.Context) error
Clear resets all cache data
func (*ChainCache) Delete ¶
func (c *ChainCache) Delete(ctx context.Context, key interface{}) error
Delete removes a value from all available caches
func (*ChainCache) Get ¶
func (c *ChainCache) Get(ctx context.Context, 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) Invalidate ¶
func (c *ChainCache) Invalidate(ctx context.Context, options store.InvalidateOptions) error
Invalidate invalidates cache item from given options
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 ¶
func (c *LoadableCache) Clear(ctx context.Context) error
Clear resets all cache data
func (*LoadableCache) Close ¶ added in v2.2.0
func (c *LoadableCache) Close() error
func (*LoadableCache) Delete ¶
func (c *LoadableCache) Delete(ctx context.Context, key interface{}) error
Delete removes a value from cache
func (*LoadableCache) Get ¶
func (c *LoadableCache) Get(ctx context.Context, 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 ¶
func (c *LoadableCache) Invalidate(ctx context.Context, options store.InvalidateOptions) error
Invalidate invalidates cache item from given options
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 ¶
func (c *MetricCache) Clear(ctx context.Context) error
Clear resets all cache data
func (*MetricCache) Delete ¶
func (c *MetricCache) Delete(ctx context.Context, key interface{}) error
Delete removes a value from the cache
func (*MetricCache) Get ¶
func (c *MetricCache) Get(ctx context.Context, key interface{}) (interface{}, error)
Get obtains a value from cache and also records metrics
func (*MetricCache) Invalidate ¶
func (c *MetricCache) Invalidate(ctx context.Context, options store.InvalidateOptions) error
Invalidate invalidates cache item from given options
type SetterCacheInterface ¶
type SetterCacheInterface interface { CacheInterface GetWithTTL(ctx context.Context, key interface{}) (interface{}, time.Duration, error) GetCodec() codec.CodecInterface }
SetterCacheInterface represents the interface for caches that allows storage (for instance: memory, redis, ...)