Documentation
¶
Index ¶
- type HybridCache
- func (c *HybridCache[V]) Algorithm() (mainCacheAlgorithm string, missingCacheAlgorithm string)
- func (c *HybridCache[V]) Capacity() (mainCacheCapacity int, missingCacheCapacity int)
- func (c *HybridCache[V]) DeleteByPrefix(prefix string) (int, error)
- func (c *HybridCache[V]) DeleteMany(keys []string) (map[string]bool, error)
- func (c *HybridCache[V]) FullKey(key string) string
- func (c *HybridCache[V]) Get(key string) (value V, found bool, err error)
- func (c *HybridCache[V]) Keys() ([]string, error)
- func (c *HybridCache[V]) Purge() error
- func (c *HybridCache[V]) SetWithTTL(key string, v V, ttl time.Duration) error
- type HybridCacheConfig
- type IntCodec
- type JSONCodec
- type Namespace
- type StringCodec
- type ValueCodec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HybridCache ¶
type HybridCache[V any] struct { // contains filtered or unexported fields }
HybridCache is a small helper that uses Redis when enabled, otherwise falls back to in-memory hot cache.
func NewHybridCache ¶
func NewHybridCache[V any](cfg HybridCacheConfig[V]) *HybridCache[V]
func (*HybridCache[V]) Algorithm ¶
func (c *HybridCache[V]) Algorithm() (mainCacheAlgorithm string, missingCacheAlgorithm string)
func (*HybridCache[V]) Capacity ¶
func (c *HybridCache[V]) Capacity() (mainCacheCapacity int, missingCacheCapacity int)
func (*HybridCache[V]) DeleteByPrefix ¶
func (c *HybridCache[V]) DeleteByPrefix(prefix string) (int, error)
func (*HybridCache[V]) DeleteMany ¶
func (c *HybridCache[V]) DeleteMany(keys []string) (map[string]bool, error)
DeleteMany accepts either fully namespaced keys or raw keys and deletes them. It returns a map keyed by fully namespaced keys.
func (*HybridCache[V]) FullKey ¶
func (c *HybridCache[V]) FullKey(key string) string
func (*HybridCache[V]) Get ¶
func (c *HybridCache[V]) Get(key string) (value V, found bool, err error)
func (*HybridCache[V]) Keys ¶
func (c *HybridCache[V]) Keys() ([]string, error)
Keys returns keys with valid values. In Redis, it returns all matching keys.
func (*HybridCache[V]) Purge ¶
func (c *HybridCache[V]) Purge() error
func (*HybridCache[V]) SetWithTTL ¶
func (c *HybridCache[V]) SetWithTTL(key string, v V, ttl time.Duration) error
type HybridCacheConfig ¶
type HybridCacheConfig[V any] struct { Namespace Namespace // Redis is used when RedisEnabled returns true (or RedisEnabled is nil) and Redis is not nil. Redis *redis.Client RedisCodec ValueCodec[V] RedisEnabled func() bool // Memory builds a hot cache used when Redis is disabled. Keys stored in memory are fully namespaced. Memory func() *hot.HotCache[string, V] }
type Namespace ¶
type Namespace string
Namespace isolates keys between different cache use-cases. (e.g. "channel_affinity:v1").
func (Namespace) MatchPattern ¶
type StringCodec ¶
type StringCodec struct{}
Click to show internal directories.
Click to hide internal directories.