cache

package
v2.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 24 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// CLIFlagRedisCompress is a cli flag name to define the redis compression setting for data sent to redis
	CLIFlagRedisCompress = "redis-compress"
)

Variables

View Source
var (
	ErrCacheMiss      = errors.New("cache: key is missing")
	ErrCacheKeyLocked = errors.New("cache: key is locked")
	CacheLockedValue  = "locked"
)

Functions

func AddCacheFlagsToCmd

func AddCacheFlagsToCmd(cmd *cobra.Command, opts ...Options) func() (*Cache, error)

AddCacheFlagsToCmd adds flags which control caching to the specified command

func CollectMetrics

func CollectMetrics(client *redis.Client, registry MetricsRegistry)

CollectMetrics add transport wrapper that pushes metrics into the specified metrics registry

func NewArgoRedisHook added in v2.2.0

func NewArgoRedisHook(reconnectCallback func()) *argoRedisHooks

func NewTwoLevelClient

func NewTwoLevelClient(client CacheClient, inMemoryExpiration time.Duration) *twoLevelClient

NewTwoLevelClient creates cache client that proxies requests to given external cache and tries to minimize number of requests to external client by storing cache entries in local in-memory cache.

Types

type Cache

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

Cache provides strongly types methods to store and retrieve values from shared cache

func NewCache

func NewCache(client CacheClient) *Cache

func (*Cache) GetClient

func (c *Cache) GetClient() CacheClient

func (*Cache) GetItem

func (c *Cache) GetItem(key string, item interface{}) error

func (*Cache) NotifyUpdated

func (c *Cache) NotifyUpdated(key string) error

func (*Cache) OnUpdated

func (c *Cache) OnUpdated(ctx context.Context, key string, callback func() error) error

func (*Cache) RenameItem added in v2.11.0

func (c *Cache) RenameItem(oldKey string, newKey string, expiration time.Duration) error

func (*Cache) SetClient

func (c *Cache) SetClient(client CacheClient)

func (*Cache) SetItem

func (c *Cache) SetItem(key string, item interface{}, opts *CacheActionOpts) error

Sets or deletes an item in cache

type CacheActionOpts added in v2.11.0

type CacheActionOpts struct {
	// Delete item from cache
	Delete bool
	// Disable writing if key already exists (NX)
	DisableOverwrite bool
	// Expiration is the cache expiration time.
	Expiration time.Duration
}

type CacheClient

type CacheClient interface {
	Set(item *Item) error
	Rename(oldKey string, newKey string, expiration time.Duration) error
	Get(key string, obj interface{}) error
	Delete(key string) error
	OnUpdated(ctx context.Context, key string, callback func() error) error
	NotifyUpdated(key string) error
}

func NewRedisCache

func NewRedisCache(client *redis.Client, expiration time.Duration, compressionType RedisCompressionType) CacheClient

type InMemoryCache

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

func NewInMemoryCache

func NewInMemoryCache(expiration time.Duration) *InMemoryCache

func (*InMemoryCache) Delete

func (i *InMemoryCache) Delete(key string) error

func (*InMemoryCache) Flush

func (i *InMemoryCache) Flush()

func (*InMemoryCache) Get

func (i *InMemoryCache) Get(key string, obj interface{}) error

func (*InMemoryCache) HasSame

func (i *InMemoryCache) HasSame(key string, obj interface{}) (bool, error)

HasSame returns true if key with the same value already present in cache

func (*InMemoryCache) Items

func (i *InMemoryCache) Items(createNewObject func() interface{}) (map[string]interface{}, error)

Items return a list of items in the cache; requires passing a constructor function so that the items can be decoded from gob format.

func (*InMemoryCache) NotifyUpdated

func (i *InMemoryCache) NotifyUpdated(key string) error

func (*InMemoryCache) OnUpdated

func (i *InMemoryCache) OnUpdated(ctx context.Context, key string, callback func() error) error

func (*InMemoryCache) Rename added in v2.11.0

func (i *InMemoryCache) Rename(oldKey string, newKey string, expiration time.Duration) error

func (*InMemoryCache) Set

func (i *InMemoryCache) Set(item *Item) error

type Item

type Item struct {
	Key             string
	Object          interface{}
	CacheActionOpts CacheActionOpts
}

type MetricsRegistry

type MetricsRegistry interface {
	IncRedisRequest(failed bool)
	ObserveRedisRequestDuration(duration time.Duration)
}

type Options added in v2.11.0

type Options struct {
	FlagPrefix      string
	OnClientCreated func(client *redis.Client)
}

type RedisCompressionType added in v2.5.0

type RedisCompressionType string
var (
	RedisCompressionNone RedisCompressionType = "none"
	RedisCompressionGZip RedisCompressionType = "gzip"
)

func CompressionTypeFromString added in v2.5.0

func CompressionTypeFromString(s string) (RedisCompressionType, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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