Versions in this module Expand all Collapse all v0 v0.3.0 Jan 13, 2026 v0.2.0 Jan 13, 2026 v0.1.0 Jan 13, 2026 Changes in this version + var ErrCacheMiss = errors.New("cache miss") + type Cache interface + Close func() error + Decr func(ctx context.Context, key string) (int64, error) + Delete func(ctx context.Context, key string) error + DeletePattern func(ctx context.Context, pattern string) error + Exists func(ctx context.Context, key string) (bool, error) + Get func(ctx context.Context, key string) ([]byte, error) + GetJSON func(ctx context.Context, key string, dest any) error + GetOrSet func(ctx context.Context, key string, ttl time.Duration, fn func() (any, error)) (any, error) + Health func(ctx context.Context) error + Incr func(ctx context.Context, key string) (int64, error) + Keys func(ctx context.Context, pattern string) ([]string, error) + MGet func(ctx context.Context, keys ...string) ([][]byte, error) + MSet func(ctx context.Context, items map[string][]byte, ttl time.Duration) error + Set func(ctx context.Context, key string, value []byte, ttl time.Duration) error + SetJSON func(ctx context.Context, key string, value any, ttl time.Duration) error + Stats func() Stats + func New(cfg Config) (Cache, error) + type Config struct + ClusterAddrs []string + ClusterMode bool + DB int + DefaultTTL time.Duration + MaxItems int + MaxMemory int64 + MaxRetries int + MinIdleConns int + Password string + PoolSize int + Prefix string + Type string + URL string + func DefaultConfig() Config + type MemoryCache struct + func NewMemoryCache(cfg Config) *MemoryCache + func (c *MemoryCache) Cleanup() + func (c *MemoryCache) Clear() + func (c *MemoryCache) Close() error + func (c *MemoryCache) Decr(ctx context.Context, key string) (int64, error) + func (c *MemoryCache) Delete(ctx context.Context, key string) error + func (c *MemoryCache) DeletePattern(ctx context.Context, pattern 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) GetJSON(ctx context.Context, key string, dest any) error + func (c *MemoryCache) GetOrSet(ctx context.Context, key string, ttl time.Duration, fn func() (any, error)) (any, error) + func (c *MemoryCache) Health(ctx context.Context) error + func (c *MemoryCache) Incr(ctx context.Context, key string) (int64, error) + func (c *MemoryCache) Keys(ctx context.Context, pattern string) ([]string, error) + func (c *MemoryCache) MGet(ctx context.Context, keys ...string) ([][]byte, error) + func (c *MemoryCache) MSet(ctx context.Context, items map[string][]byte, ttl time.Duration) error + func (c *MemoryCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error + func (c *MemoryCache) SetJSON(ctx context.Context, key string, value any, ttl time.Duration) error + func (c *MemoryCache) Stats() Stats + type Middleware struct + func NewMiddleware(cache Cache) *Middleware + func (m *Middleware) Handler(ttl time.Duration) func(http.Handler) http.Handler + func (m *Middleware) HandlerWithKeyFunc(ttl time.Duration, keyFunc func(*http.Request) string) func(http.Handler) http.Handler + func (m *Middleware) Invalidate(r *http.Request) error + func (m *Middleware) InvalidatePattern(pattern string) error + type RedisCache struct + func NewRedisCache(cfg Config) (*RedisCache, error) + func (c *RedisCache) Close() error + func (c *RedisCache) Decr(ctx context.Context, key string) (int64, error) + func (c *RedisCache) Delete(ctx context.Context, key string) error + func (c *RedisCache) DeletePattern(ctx context.Context, pattern string) error + func (c *RedisCache) Exists(ctx context.Context, key string) (bool, error) + func (c *RedisCache) Get(ctx context.Context, key string) ([]byte, error) + func (c *RedisCache) GetJSON(ctx context.Context, key string, dest any) error + func (c *RedisCache) GetOrSet(ctx context.Context, key string, ttl time.Duration, fn func() (any, error)) (any, error) + func (c *RedisCache) Health(ctx context.Context) error + func (c *RedisCache) Incr(ctx context.Context, key string) (int64, error) + func (c *RedisCache) Keys(ctx context.Context, pattern string) ([]string, error) + func (c *RedisCache) MGet(ctx context.Context, keys ...string) ([][]byte, error) + func (c *RedisCache) MSet(ctx context.Context, items map[string][]byte, ttl time.Duration) error + func (c *RedisCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error + func (c *RedisCache) SetJSON(ctx context.Context, key string, value any, ttl time.Duration) error + func (c *RedisCache) Stats() Stats + type Stats struct + Hits int64 + Keys int64 + MemoryUsed int64 + Misses int64