Versions in this module Expand all Collapse all v1 v1.0.3 Aug 21, 2025 v1.0.2 Aug 20, 2025 Changes in this version + type BasicCacheMetrics struct + func NewBasicCacheMetrics() *BasicCacheMetrics + func (m *BasicCacheMetrics) GetStats() map[string]interface{} + func (m *BasicCacheMetrics) RecordError(operation string) + func (m *BasicCacheMetrics) RecordOperation(operation, key string) + func (m *BasicCacheMetrics) RecordOperationWithDuration(operation, key string, duration time.Duration) + func (m *BasicCacheMetrics) Reset() + type CacheKey struct + Entity string + ID string + Prefix string + Service string + Suffix string + Tenant string + Version string + func ConfigCacheKey(service, configType string, tenant ...string) CacheKey + func QueryCacheKey(service, queryType, hash string, tenant ...string) CacheKey + func SessionCacheKey(sessionID string, tenant ...string) CacheKey + func UserCacheKey(userID, dataType string, tenant ...string) CacheKey + func (ck CacheKey) Pattern() string + func (ck CacheKey) String() string type CacheMetrics + BusinessMetrics map[string]int64 + CompressionRatio float64 + Deletes int64 + Errors int64 + EvictionCount int64 + HitRatio float64 + Hits int64 + LatencySum int64 + Misses int64 + NetworkErrors int64 + OperationCount int64 + QueryCacheHits int64 + SessionCacheHits int64 + Sets int64 + TimeoutErrors int64 + UserCacheHits int64 + type CacheWrapper struct + func NewCacheWrapper(manager *RedisManager, namespace string) *CacheWrapper + func (cw *CacheWrapper) GetMetrics() map[string]interface{} + func (cw *CacheWrapper) GetMultiple(ctx context.Context, keys []CacheKey) (map[string]interface{}, error) + func (cw *CacheWrapper) GetOrSet(ctx context.Context, key CacheKey, dataType string, ...) (interface{}, error) + func (cw *CacheWrapper) GetOrSetJSON(ctx context.Context, key CacheKey, dataType string, target interface{}, ...) error + func (cw *CacheWrapper) InvalidatePattern(ctx context.Context, pattern CacheKey) error + func (cw *CacheWrapper) Lock(ctx context.Context, lockKey string, ttl time.Duration) (*DistributedLock, error) + func (cw *CacheWrapper) RefreshCache(ctx context.Context, key CacheKey, dataType string, ...) error + func (cw *CacheWrapper) SetMultiple(ctx context.Context, entries map[CacheKey]MultipleEntry) error + func (cw *CacheWrapper) WarmCache(ctx context.Context, warmupData map[CacheKey]WarmupEntry) error + type CircuitBreaker struct + type Config struct + AlertManager *monitoring.AlertManager + BaseConfig *config.BaseConfig + ClusterAddrs []string + DB int + DialTimeout time.Duration + EnableCircuitBreaker bool + EnableCompression bool + EnableEncryption bool + EnablePrometheusMetrics bool + EnableRetryPolicy bool + EncryptionKey string + HealthCheckInterval time.Duration + Host string + MaxConnAge time.Duration + MaxFailureThreshold int + MaxRetries int + MetricsNamespace string + MinIdleConns int + Mode string + Namespace string + Password string + PoolSize int + PoolTimeout time.Duration + Port string + ReadTimeout time.Duration + TTL time.Duration + WriteTimeout time.Duration + func LoadConfigFromBase(baseConfig *config.BaseConfig, serviceName string) *Config + type DistributedLock struct + func NewDistributedLock(manager *RedisManager, key string, ttl time.Duration) (*DistributedLock, error) + func (dl *DistributedLock) Acquire(ctx context.Context) error + func (dl *DistributedLock) Release(ctx context.Context) error + type MultipleEntry struct + Data interface{} + DataType string + type PerformanceStats struct + AverageLatency float64 + LastUpdated time.Time + P95Latency float64 + P99Latency float64 + ThroughputPerSecond float64 + TotalOperations int64 + type RedisManager struct + func GetInstance(config *Config) (*RedisManager, error) + func NewRedisManager(config *Config) (*RedisManager, error) + func (rm *RedisManager) Close() error + func (rm *RedisManager) Delete(ctx context.Context, keys ...string) error + func (rm *RedisManager) DeletePattern(ctx context.Context, pattern string) error + func (rm *RedisManager) Get(ctx context.Context, key string) (string, error) + func (rm *RedisManager) GetJSON(ctx context.Context, key string, dest interface{}) error + func (rm *RedisManager) GetMetrics() map[string]interface{} + func (rm *RedisManager) Health(ctx context.Context) error + func (rm *RedisManager) Set(ctx context.Context, key string, value interface{}) error + func (rm *RedisManager) SetNX(ctx context.Context, key string, value interface{}, ttl time.Duration) (bool, error) + func (rm *RedisManager) SetWithTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) error + type RetryPolicy struct + BackoffFactor float64 + InitialDelay time.Duration + MaxAttempts int + MaxDelay time.Duration + RetryCondition func(error) bool + type TTLCalculator struct + func NewTTLCalculator(baseTTL time.Duration) *TTLCalculator + func (tc *TTLCalculator) CalculateTTL(dataType string, accessCount int64) time.Duration + type TTLStrategy struct + AccessBased bool + MaxTTL time.Duration + MinTTL time.Duration + Multiplier float64 + Randomness float64 + type WarmupEntry struct + DataType string + LoadFunc func() (interface{}, error) + type WrapperMetrics struct + CompressionSavings int64 + DeserializationErrors int64 + FallbackHits int64 + SerializationErrors int64 v1.0.1 Aug 10, 2025 v1.0.0 Aug 10, 2025 Changes in this version + var ErrCacheDisabled = fmt.Errorf("cache is disabled") + type CacheService struct + func NewCacheService(client *RedisClient, logger logger.Logger) *CacheService + func (cs *CacheService) GetOrSet(ctx context.Context, key string, dest interface{}, ...) error + type Client interface + Close func() error + Decrement func(ctx context.Context, key string) (int64, error) + Delete func(ctx context.Context, keys ...string) error + Exists func(ctx context.Context, key string) (bool, error) + Expire func(ctx context.Context, key string, expiration time.Duration) error + FlushDB func(ctx context.Context) error + Get func(ctx context.Context, key string) (string, error) + GetJSON func(ctx context.Context, key string, dest interface{}) error + GetSet func(ctx context.Context, key string, value interface{}) (string, error) + HDel func(ctx context.Context, key string, fields ...string) error + HExists func(ctx context.Context, key, field string) (bool, error) + HGet func(ctx context.Context, key, field string) (string, error) + HGetAll func(ctx context.Context, key string) (map[string]string, error) + HSet func(ctx context.Context, key string, values ...interface{}) error + Increment func(ctx context.Context, key string) (int64, error) + Keys func(ctx context.Context, pattern string) ([]string, error) + LLen func(ctx context.Context, key string) (int64, error) + LPop func(ctx context.Context, key string) (string, error) + LPush func(ctx context.Context, key string, values ...interface{}) error + LRange func(ctx context.Context, key string, start, stop int64) ([]string, error) + Ping func(ctx context.Context) error + RPop func(ctx context.Context, key string) (string, error) + RPush func(ctx context.Context, key string, values ...interface{}) error + SAdd func(ctx context.Context, key string, members ...interface{}) error + SIsMember func(ctx context.Context, key string, member interface{}) (bool, error) + SMembers func(ctx context.Context, key string) ([]string, error) + SRem func(ctx context.Context, key string, members ...interface{}) error + Set func(ctx context.Context, key string, value interface{}, expiration time.Duration) error + SetJSON func(ctx context.Context, key string, value interface{}, expiration time.Duration) error + SetNX func(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error) + func NewRedisClient(config *RedisConfig) (Client, error) + type RedisClient struct + func (rc *RedisClient) Close() error + func (rc *RedisClient) Delete(ctx context.Context, key string) error + func (rc *RedisClient) Exists(ctx context.Context, key string) (bool, error) + func (rc *RedisClient) Expire(ctx context.Context, key string, ttl time.Duration) error + func (rc *RedisClient) FlushPattern(ctx context.Context, pattern string) error + func (rc *RedisClient) Get(ctx context.Context, key string, dest interface{}) error + func (rc *RedisClient) GetClient() redis.UniversalClient + func (rc *RedisClient) GetMultiple(ctx context.Context, keys []string) (map[string]interface{}, error) + func (rc *RedisClient) GetTTL(ctx context.Context, key string) (time.Duration, error) + func (rc *RedisClient) HealthCheck() observability.HealthCheck + func (rc *RedisClient) Increment(ctx context.Context, key string) (int64, error) + func (rc *RedisClient) IncrementBy(ctx context.Context, key string, value int64) (int64, error) + func (rc *RedisClient) Ping(ctx context.Context) error + func (rc *RedisClient) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error + func (rc *RedisClient) SetNX(ctx context.Context, key string, value interface{}, ttl time.Duration) (bool, error) + type RedisConfig struct + ClusterAddrs []string + ClusterMode bool + DB int + EnableMetrics bool + Host string + IdleCheckFrequency time.Duration + IdleTimeout time.Duration + MaxConnAge time.Duration + MaxRetries int + MaxRetryBackoff time.Duration + MinIdleConns int + MinRetryBackoff time.Duration + Password string + PoolSize int + PoolTimeout time.Duration + Port int + SlowLogEnabled bool + SlowLogThreshold time.Duration + TLSEnabled bool + TLSSkipVerify bool + func DefaultRedisConfig() *RedisConfig + type RedisOptions struct + Config config.CacheConfig + Logger logger.Logger v0 v0.1.0 Aug 4, 2025 Changes in this version + var ErrCacheConnectionFailed = errors.New("cache connection failed") + var ErrCacheFull = errors.New("cache is full") + var ErrCacheMiss = errors.New("cache miss") + var ErrCacheTimeout = errors.New("cache operation timeout") + var ErrDeserializationFailed = errors.New("deserialization failed") + var ErrInvalidCacheKey = errors.New("invalid cache key") + var ErrSerializationFailed = errors.New("serialization failed") + type CacheConfig struct + DefaultExpiration time.Duration + DialTimeout time.Duration + EnableCompression bool + EnableMemoryFallback bool + EnableMetrics bool + IdleTimeout time.Duration + KeyPrefix string + MaxConnAge time.Duration + MemoryCacheSize int + MinIdleConns int + PoolSize int + PoolTimeout time.Duration + ReadTimeout time.Duration + RedisDB int + RedisHost string + RedisPassword string + RedisPort string + WriteTimeout time.Duration + func DefaultCacheConfig() *CacheConfig + type CacheInterface interface + Delete func(ctx context.Context, key string) error + Exists func(ctx context.Context, key string) bool + Get func(ctx context.Context, key string, dest interface{}) error + GetMultiple func(ctx context.Context, keys []string) (map[string]interface{}, error) + GetStats func(ctx context.Context) (map[string]interface{}, error) + GetTTL func(ctx context.Context, key string) time.Duration + Increment func(ctx context.Context, key string, delta int64) (int64, error) + InvalidatePattern func(ctx context.Context, pattern string) error + Ping func(ctx context.Context) error + Set func(ctx context.Context, key string, value interface{}, expiration time.Duration) error + SetMultiple func(ctx context.Context, items map[string]interface{}, expiration time.Duration) error + SetNX func(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error) + type CacheMetrics struct + func NewCacheMetrics() *CacheMetrics + func (m *CacheMetrics) GetStats() map[string]interface{} + func (m *CacheMetrics) RecordError(operation string) + func (m *CacheMetrics) RecordOperation(operation, key string) + func (m *CacheMetrics) RecordOperationWithDuration(operation, key string, duration time.Duration) + func (m *CacheMetrics) Reset() + type MemoryCache struct + func NewMemoryCache(maxSize int) *MemoryCache + func (c *MemoryCache) Clear() + func (c *MemoryCache) Close() + func (c *MemoryCache) Delete(key string) + func (c *MemoryCache) Exists(key string) bool + func (c *MemoryCache) Get(key string, dest interface{}) error + func (c *MemoryCache) GetStats() map[string]interface{} + func (c *MemoryCache) GetTTL(key string) time.Duration + func (c *MemoryCache) Increment(key string, delta int64) int64 + func (c *MemoryCache) InvalidatePattern(pattern string) + func (c *MemoryCache) Set(key string, value interface{}, expiration time.Duration) error + func (c *MemoryCache) SetNX(key string, value interface{}, expiration time.Duration) bool + type MemoryCacheItem struct + CreatedAt time.Time + Expiration time.Time + Value interface{} + func (item *MemoryCacheItem) IsExpired() bool + type MemoryCacheStats struct + Deletes int64 + Evictions int64 + Hits int64 + Misses int64 + Sets int64 + Size int64 + type OperationMetrics struct + Count int64 + Errors int64 + LastTime time.Time + TotalTime time.Duration + type UnifiedCache struct + func NewUnifiedCache(config *CacheConfig, logger *logrus.Logger) (*UnifiedCache, error) + func (c *UnifiedCache) Close() error + func (c *UnifiedCache) Delete(ctx context.Context, key string) error + func (c *UnifiedCache) Exists(ctx context.Context, key string) bool + func (c *UnifiedCache) Get(ctx context.Context, key string, dest interface{}) error + func (c *UnifiedCache) GetMultiple(ctx context.Context, keys []string) (map[string]interface{}, error) + func (c *UnifiedCache) GetStats(ctx context.Context) (map[string]interface{}, error) + func (c *UnifiedCache) GetTTL(ctx context.Context, key string) time.Duration + func (c *UnifiedCache) Increment(ctx context.Context, key string, delta int64) (int64, error) + func (c *UnifiedCache) InvalidatePattern(ctx context.Context, pattern string) error + func (c *UnifiedCache) Ping(ctx context.Context) error + func (c *UnifiedCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error + func (c *UnifiedCache) SetMultiple(ctx context.Context, items map[string]interface{}, expiration time.Duration) error + func (c *UnifiedCache) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)