Documentation
¶
Index ¶
- Constants
- Variables
- func AddCacheFlagsToCmd(cmd *cobra.Command, opts ...Options) func() (*Cache, error)
- func CollectMetrics(client *redis.Client, registry MetricsRegistry, lock *sync.RWMutex)
- func NewArgoRedisHook(reconnectCallback func()) *argoRedisHooks
- func NewTwoLevelClient(client CacheClient, inMemoryExpiration time.Duration) *twoLevelClient
- type Cache
- func (c *Cache) GetClient() CacheClient
- func (c *Cache) GetItem(key string, item any) error
- func (c *Cache) GetLocalItem(key string, item any) error
- func (c *Cache) InvalidateLocalItem(key string)
- func (c *Cache) NotifyUpdated(key string) error
- func (c *Cache) OnUpdated(ctx context.Context, key string, callback func() error) error
- func (c *Cache) RenameItem(oldKey string, newKey string, expiration time.Duration) error
- func (c *Cache) SetClient(client CacheClient)
- func (c *Cache) SetItem(key string, item any, opts *CacheActionOpts) error
- type CacheActionOpts
- type CacheClient
- type InMemoryCache
- func (i *InMemoryCache) Delete(key string) error
- func (i *InMemoryCache) Flush()
- func (i *InMemoryCache) Get(key string, obj any) error
- func (i *InMemoryCache) HasSame(key string, obj any) (bool, error)
- func (i *InMemoryCache) Items(createNewObject func() any) (map[string]any, error)
- func (i *InMemoryCache) NotifyUpdated(_ string) error
- func (i *InMemoryCache) OnUpdated(_ context.Context, _ string, _ func() error) error
- func (i *InMemoryCache) Rename(oldKey string, newKey string, expiration time.Duration) error
- func (i *InMemoryCache) Set(item *Item) error
- type Item
- type MetricsRegistry
- type Options
- type RedisCompressionType
Constants ¶
const (
// CLIFlagRedisCompress is a cli flag name to define the redis compression setting for data sent to redis
CLIFlagRedisCompress = "redis-compress"
)
Variables ¶
var ( ErrCacheMiss = errors.New("cache: key is missing") ErrCacheKeyLocked = errors.New("cache: key is locked") CacheLockedValue = "locked" )
Functions ¶
func AddCacheFlagsToCmd ¶
AddCacheFlagsToCmd adds flags which control caching to the specified command
func CollectMetrics ¶
func CollectMetrics(client *redis.Client, registry MetricsRegistry, lock *sync.RWMutex)
CollectMetrics add transport wrapper that pushes metrics into the specified metrics registry Lock should be shared between functions that can add/process a Redis hook.
func NewArgoRedisHook ¶
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) GetLocalItem ¶ added in v3.5.7
GetLocalItem reads the item from the client's local copy only. It returns ErrCacheMiss if the client keeps no local copy or the key is not in it.
func (*Cache) InvalidateLocalItem ¶ added in v3.5.7
InvalidateLocalItem drops the local copy of the item, if the client keeps one, so the next SetItem for that key is always written to the external cache.
func (*Cache) NotifyUpdated ¶
func (*Cache) RenameItem ¶
func (*Cache) SetClient ¶
func (c *Cache) SetClient(client CacheClient)
type CacheActionOpts ¶
type CacheClient ¶
type CacheClient interface {
Set(item *Item) error
Rename(oldKey string, newKey string, expiration time.Duration) error
Get(key string, obj any) 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) HasSame ¶
func (i *InMemoryCache) HasSame(key string, obj any) (bool, error)
HasSame returns true if key with the same value already present in cache
func (*InMemoryCache) Items ¶
func (i *InMemoryCache) Items(createNewObject func() any) (map[string]any, 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(_ string) error
func (*InMemoryCache) Set ¶
func (i *InMemoryCache) Set(item *Item) error
type Item ¶
type Item struct {
Key string
Object any
CacheActionOpts CacheActionOpts
}
type MetricsRegistry ¶
type RedisCompressionType ¶
type RedisCompressionType string
var ( RedisCompressionNone RedisCompressionType = "none" RedisCompressionGZip RedisCompressionType = "gzip" )
func CompressionTypeFromString ¶
func CompressionTypeFromString(s string) (RedisCompressionType, error)