Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateToken() (string, error)
- type CacheType
- type Client
- type Config
- type Memory
- func (c *Memory) Delete(key string) error
- func (c *Memory) Get(key string) ([]byte, error)
- func (c *Memory) Set(key string, value []byte, ttl time.Duration) error
- func (c *Memory) SetIfMatch(key string, value []byte, expected []byte, ttl time.Duration) (bool, error)
- func (c *Memory) SetNX(key string, value []byte, ttl time.Duration) (bool, error)
- func (c *Memory) Stop() error
- type MemoryConfig
- type Redis
- func (r *Redis) Delete(key string) error
- func (r *Redis) Get(key string) ([]byte, error)
- func (r *Redis) Set(key string, value []byte, ttl time.Duration) error
- func (r *Redis) SetIfMatch(key string, value []byte, expected []byte, ttl time.Duration) (bool, error)
- func (r *Redis) SetNX(key string, value []byte, ttl time.Duration) (bool, error)
- func (r *Redis) Stop() error
- type RedisConfig
Constants ¶
View Source
const ( StatusMiss = "miss" StatusError = "error" StatusHit = "hit" StatusOK = "ok" )
Status constants for metrics
View Source
const (
ErrCacheMissMsg = "key not found in cache"
)
Error message constants
Variables ¶
View Source
var ErrCacheMiss = errors.New(ErrCacheMissMsg)
Error returned when a key is not found in the cache
Functions ¶
func GenerateToken ¶
GenerateToken generates a random token for lock identification
Types ¶
type Client ¶
type Client interface {
// Get gets a value from the cache
Get(key string) ([]byte, error)
// Set sets a value in the cache
Set(key string, value []byte, ttl time.Duration) error
// SetNX sets a value in the cache only if the key doesn't exist
// Returns true if the value was set, false if it already exists
SetNX(key string, value []byte, ttl time.Duration) (bool, error)
// SetIfMatch sets a value in the cache only if the current value matches the expected value
// Returns true if the value was set, false if the current value doesn't match
SetIfMatch(key string, value []byte, expected []byte, ttl time.Duration) (bool, error)
// Delete deletes a value from the cache
Delete(key string) error
// Stop gracefully stops the cache
Stop() error
}
Client is a cache client
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory implements an in-memory cache
func NewMemory ¶
func NewMemory(config MemoryConfig, metricsSvc *metrics.Metrics) *Memory
NewMemory creates a new memory cache
func (*Memory) SetIfMatch ¶
func (c *Memory) SetIfMatch(key string, value []byte, expected []byte, ttl time.Duration) (bool, error)
SetIfMatch sets a value in the cache only if the current value matches expected (atomic operation)
type MemoryConfig ¶
MemoryConfig contains configuration for memory cache
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis is a Redis-backed cache implementation
func NewRedis ¶
func NewRedis(config RedisConfig, metricsSvc *metrics.Metrics) (*Redis, error)
NewRedis creates a new Redis cache
func (*Redis) SetIfMatch ¶
func (r *Redis) SetIfMatch(key string, value []byte, expected []byte, ttl time.Duration) (bool, error)
SetIfMatch sets a value in Redis only if the current value matches expected (atomic operation)
type RedisConfig ¶
type RedisConfig struct {
URL string `yaml:"url"` // Redis connection URL
DefaultTTL time.Duration `yaml:"defaultTTL"` // Default TTL for cache items
}
RedisConfig contains configuration for Redis cache
Click to show internal directories.
Click to hide internal directories.