Documentation
¶
Index ¶
- type Cache
- type HybridCache
- func (c *HybridCache) BLPop(ctx context.Context, timeout time.Duration, keys ...string) ([]string, error)
- func (c *HybridCache) Close() error
- func (c *HybridCache) Del(ctx context.Context, key string) error
- func (c *HybridCache) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
- func (c *HybridCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *HybridCache) Get(ctx context.Context, key string) (string, error)
- func (c *HybridCache) GetOrSet(ctx context.Context, key string, expiration time.Duration, ...) (string, error)
- func (c *HybridCache) GetRedisClient() *redis.Client
- func (c *HybridCache) Incr(ctx context.Context, key string) (int64, error)
- func (c *HybridCache) LTrim(ctx context.Context, key string, start, stop int64) error
- func (c *HybridCache) RPush(ctx context.Context, key string, values ...interface{}) error
- func (c *HybridCache) SAdd(ctx context.Context, key string, members ...interface{}) error
- func (c *HybridCache) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
- func (c *HybridCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- func (c *HybridCache) Stats(ctx context.Context) map[string]interface{}
- type RedisCache
- func (c *RedisCache) BLPop(ctx context.Context, timeout time.Duration, keys ...string) ([]string, error)
- func (c *RedisCache) Client() *redis.Client
- func (c *RedisCache) Close() error
- func (c *RedisCache) Del(ctx context.Context, key string) error
- func (c *RedisCache) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
- func (c *RedisCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *RedisCache) Get(ctx context.Context, key string) (string, error)
- func (c *RedisCache) GetOrSet(ctx context.Context, key string, expiration time.Duration, ...) (string, error)
- func (c *RedisCache) Incr(ctx context.Context, key string) (int64, error)
- func (c *RedisCache) LTrim(ctx context.Context, key string, start, stop int64) error
- func (c *RedisCache) RPush(ctx context.Context, key string, values ...interface{}) error
- func (c *RedisCache) SAdd(ctx context.Context, key string, members ...interface{}) error
- func (c *RedisCache) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
- func (c *RedisCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- func (c *RedisCache) Stats(ctx context.Context) map[string]interface{}
- type RistrettoCache
- func (c *RistrettoCache) BLPop(ctx context.Context, timeout time.Duration, keys ...string) ([]string, error)
- func (c *RistrettoCache) Close() error
- func (c *RistrettoCache) Del(ctx context.Context, key string) error
- func (c *RistrettoCache) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
- func (c *RistrettoCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *RistrettoCache) Get(ctx context.Context, key string) (string, error)
- func (c *RistrettoCache) GetOrSet(ctx context.Context, key string, expiration time.Duration, ...) (string, error)
- func (c *RistrettoCache) Incr(ctx context.Context, key string) (int64, error)
- func (c *RistrettoCache) LTrim(ctx context.Context, key string, start, stop int64) error
- func (c *RistrettoCache) RPush(ctx context.Context, key string, values ...interface{}) error
- func (c *RistrettoCache) SAdd(ctx context.Context, key string, members ...interface{}) error
- func (c *RistrettoCache) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
- func (c *RistrettoCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- func (c *RistrettoCache) Stats(ctx context.Context) map[string]interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
Get(ctx context.Context, key string) (string, error)
Exists(ctx context.Context, key string) (bool, error)
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
Del(ctx context.Context, key string) error
Incr(ctx context.Context, key string) (int64, error)
RPush(ctx context.Context, key string, values ...interface{}) error
BLPop(ctx context.Context, timeout time.Duration, keys ...string) ([]string, error)
LTrim(ctx context.Context, key string, start, stop int64) error
Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
SAdd(ctx context.Context, key string, members ...interface{}) error
SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
// GetOrSet retrieves the value from cache or executes the fetch function, catching stampedes
GetOrSet(ctx context.Context, key string, expiration time.Duration, fetch func() (string, error)) (string, error)
// Stats returns cache statistics
Stats(ctx context.Context) map[string]interface{}
Close() error
}
Cache interface defines the methods for caching
type HybridCache ¶
type HybridCache struct {
// contains filtered or unexported fields
}
HybridCache combines local (L1) and remote (L2) caching
func NewHybridCache ¶
func NewHybridCache(local Cache, remote Cache) *HybridCache
NewHybridCache creates a new HybridCache
func (*HybridCache) Close ¶
func (c *HybridCache) Close() error
func (*HybridCache) GetRedisClient ¶
func (c *HybridCache) GetRedisClient() *redis.Client
GetRedisClient attempts to return the underlying Redis client if available
func (*HybridCache) RPush ¶
func (c *HybridCache) RPush(ctx context.Context, key string, values ...interface{}) error
func (*HybridCache) SAdd ¶
func (c *HybridCache) SAdd(ctx context.Context, key string, members ...interface{}) error
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache implements Cache using Redis
func NewRedisCache ¶
func NewRedisCache(client *redis.Client) *RedisCache
NewRedisCache creates a new RedisCache
func (*RedisCache) Client ¶
func (c *RedisCache) Client() *redis.Client
Client returns the underlying redis client
func (*RedisCache) Close ¶
func (c *RedisCache) Close() error
func (*RedisCache) RPush ¶
func (c *RedisCache) RPush(ctx context.Context, key string, values ...interface{}) error
func (*RedisCache) SAdd ¶
func (c *RedisCache) SAdd(ctx context.Context, key string, members ...interface{}) error
type RistrettoCache ¶
type RistrettoCache struct {
// contains filtered or unexported fields
}
RistrettoCache implements cache.Cache using In-Process Memory (Ristretto)
func NewRistrettoCache ¶
func NewRistrettoCache(maxKeys int64) (*RistrettoCache, error)
NewRistrettoCache creates a new RistrettoCache
func (*RistrettoCache) Close ¶
func (c *RistrettoCache) Close() error
func (*RistrettoCache) GetOrSet ¶
func (c *RistrettoCache) GetOrSet(ctx context.Context, key string, expiration time.Duration, fetch func() (string, error)) (string, error)
GetOrSet for L1
func (*RistrettoCache) Incr ¶
No-op for Redis specific methods (List, Set, Eval, etc.) If these are called on L1, they will error or panic. Ideally usage of L1 is mostly KV.
func (*RistrettoCache) RPush ¶
func (c *RistrettoCache) RPush(ctx context.Context, key string, values ...interface{}) error
func (*RistrettoCache) SAdd ¶
func (c *RistrettoCache) SAdd(ctx context.Context, key string, members ...interface{}) error
Click to show internal directories.
Click to hide internal directories.