Documentation
¶
Overview ¶
Package cache provides service with pluggable cache abstraction
Index ¶
- Variables
- type Cacher
- type Config
- type Error
- type RedisCache
- func (c *RedisCache) Delete(ctx context.Context, pattern bool, keys ...string) error
- func (c *RedisCache) Expire(ctx context.Context, key string, expiration time.Duration) error
- func (c *RedisCache) Get(ctx context.Context, key string, ptrValue interface{}) error
- func (c *RedisCache) KeyExists(ctx context.Context, key string) (bool, error)
- func (c *RedisCache) Set(ctx context.Context, key string, value interface{}, expires time.Duration) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrCacheMiss is a replacement for implementation defined cache miss error of different providers, // such as replacement for redis.Nil which looks meaningless ErrCacheMiss = errors.New("cache: key not found") )
Functions ¶
This section is empty.
Types ¶
type Cacher ¶
type Cacher interface { // Get Retrieves the content associated with the given key. decoding it into the given // pointer. // // Returns: // - nil if the value was successfully retrieved and ptrValue set // - ErrCacheMiss if the value was not in the cache // - an implementation specific error otherwise Get(ctx context.Context, key string, ptrValue interface{}) error // Set the given key/value in the cache, overwriting any existing value // associated with that key // if broadcasting mode is specified sends related errors to returned channel during cache initialization Set(ctx context.Context, key string, value interface{}, expires time.Duration) error // Delete deletes the specified keys from the cache // if pattern is true, then keys is treated as a pattern and all keys matching the pattern will be deleted Delete(ctx context.Context, pattern bool, keys ...string) error // KeyExists verifies whether specified key exists in cache; returns true in case key exists and nil error KeyExists(ctx context.Context, key string) (bool, error) // Expire use this when you want time to live of a key will be updated to the new value Expire(ctx context.Context, key string, expiration time.Duration) error }
Cacher is an interface which abstracts cache providers details for mockability and usability
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache wraps *redis.Client to meet swappable and mockable Cache interface
func (*RedisCache) Get ¶
func (c *RedisCache) Get(ctx context.Context, key string, ptrValue interface{}) error
Get retrieves value from Redis and serializes to pointer value
func (*RedisCache) KeyExists ¶
KeyExists checks whether specified key exists; returns true and nil if key is actually exists
func (*RedisCache) Set ¶
func (c *RedisCache) Set(ctx context.Context, key string, value interface{}, expires time.Duration) error
Set takes key and value as input and setting Redis cache with this value shares errors to channel in case broadcasting mode is enabled it prevents manual error handling which seems noisy and unnecessary in rdb code
Click to show internal directories.
Click to hide internal directories.