Documentation
¶
Index ¶
- func GetJSON(ctx context.Context, c Cache, key string, v interface{}) error
- func SetJSON(ctx context.Context, c Cache, key string, v interface{}, ttl time.Duration) error
- type Cache
- type Config
- type MemoryCache
- func (c *MemoryCache) Clear(ctx context.Context, pattern string) error
- func (c *MemoryCache) Close() error
- func (c *MemoryCache) Delete(ctx context.Context, key string) error
- func (c *MemoryCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *MemoryCache) Get(ctx context.Context, key string) ([]byte, error)
- func (c *MemoryCache) Ping(ctx context.Context) error
- func (c *MemoryCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (c *MemoryCache) Stats(ctx context.Context) (*Stats, error)
- type RedisCache
- func (c *RedisCache) Clear(ctx context.Context, pattern string) error
- func (c *RedisCache) Close() error
- func (c *RedisCache) Delete(ctx context.Context, key string) error
- func (c *RedisCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *RedisCache) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (c *RedisCache) Get(ctx context.Context, key string) ([]byte, error)
- func (c *RedisCache) HGet(ctx context.Context, key, field string) ([]byte, error)
- func (c *RedisCache) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (c *RedisCache) HSet(ctx context.Context, key, field string, value []byte) error
- func (c *RedisCache) Incr(ctx context.Context, key string) (int64, error)
- func (c *RedisCache) Ping(ctx context.Context) error
- func (c *RedisCache) Publish(ctx context.Context, channel string, message []byte) error
- func (c *RedisCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (c *RedisCache) SetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error)
- func (c *RedisCache) Stats(ctx context.Context) (*Stats, error)
- func (c *RedisCache) Subscribe(ctx context.Context, channel string) *redis.PubSub
- type RedisConfig
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache interface {
// Get retrieves a value from the cache
Get(ctx context.Context, key string) ([]byte, error)
// Set stores a value in the cache with TTL
Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
// Delete removes a value from the cache
Delete(ctx context.Context, key string) error
// Exists checks if a key exists
Exists(ctx context.Context, key string) (bool, error)
// Clear removes all keys matching a pattern
Clear(ctx context.Context, pattern string) error
// Close closes the cache connection
Close() error
// Ping checks cache connectivity
Ping(ctx context.Context) error
// Stats returns cache statistics
Stats(ctx context.Context) (*Stats, error)
}
Cache is the interface for cache implementations
type Config ¶
type Config struct {
// Type: none (disabled), memory (default), valkey, redis
Type string `yaml:"type"`
// Connection URL (takes precedence over host/port)
URL string `yaml:"url"`
// Individual connection settings
Host string `yaml:"host"`
Port int `yaml:"port"`
Password string `yaml:"password"`
DB int `yaml:"db"`
// Pool settings
PoolSize int `yaml:"pool_size"`
MinIdle int `yaml:"min_idle"`
Timeout time.Duration `yaml:"timeout"`
// Key prefix
Prefix string `yaml:"prefix"`
// Default TTL
TTL int `yaml:"ttl"` // seconds
// Cluster mode
Cluster bool `yaml:"cluster"`
ClusterNodes []string `yaml:"cluster_nodes"`
// Memory cache specific
MaxSize int `yaml:"max_size"` // Max items for memory cache
}
Config holds cache configuration per AI.md PART 18
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache implements Cache interface using in-memory storage
func NewMemoryCache ¶
func NewMemoryCache(maxSize int, defaultTTL time.Duration) *MemoryCache
NewMemoryCache creates a new memory cache
func (*MemoryCache) Clear ¶
func (c *MemoryCache) Clear(ctx context.Context, pattern string) error
Clear removes all keys matching a pattern
func (*MemoryCache) Close ¶
func (c *MemoryCache) Close() error
Close closes the cache (no-op for memory cache)
func (*MemoryCache) Delete ¶
func (c *MemoryCache) Delete(ctx context.Context, key string) error
Delete removes a value from the cache
func (*MemoryCache) Ping ¶
func (c *MemoryCache) Ping(ctx context.Context) error
Ping checks cache connectivity (always succeeds for memory cache)
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache implements Cache interface using Valkey/Redis Per AI.md PART 18: Uses github.com/redis/go-redis/v9
func NewRedisCache ¶
func NewRedisCache(cfg *RedisConfig) (*RedisCache, error)
NewRedisCache creates a new Redis/Valkey cache
func (*RedisCache) Clear ¶
func (c *RedisCache) Clear(ctx context.Context, pattern string) error
Clear removes all keys matching a pattern
func (*RedisCache) Delete ¶
func (c *RedisCache) Delete(ctx context.Context, key string) error
Delete removes a value from Redis
func (*RedisCache) Ping ¶
func (c *RedisCache) Ping(ctx context.Context) error
Ping checks Redis connectivity
func (*RedisCache) SetNX ¶
func (c *RedisCache) SetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error)
SetNX sets a key only if it doesn't exist (for distributed locking)
type RedisConfig ¶
type RedisConfig struct {
// Type: "redis" or "valkey" (same library, just for clarity)
Type string
// Connection URL (takes precedence over host/port)
// Format: redis://user:password@host:port/db or valkey://...
URL string
// Individual connection settings
Host string
Port int
Password string
DB int
// Pool settings
PoolSize int
MinIdle int
Timeout time.Duration
// Key prefix
Prefix string
// Cluster mode
Cluster bool
ClusterNodes []string
}
RedisConfig holds Redis/Valkey connection configuration