Documentation
¶
Index ¶
- type Cache
- type CacheItem
- type CacheManager
- type MemoryCache
- func (c *MemoryCache) Clear(ctx context.Context) 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) GetJSON(ctx context.Context, key string, dest interface{}) error
- func (c *MemoryCache) GetWithTTL(ctx context.Context, key string) ([]byte, time.Duration, error)
- func (c *MemoryCache) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
- func (c *MemoryCache) SetJSON(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- type RedisCache
- func (c *RedisCache) Clear(ctx context.Context) 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) Get(ctx context.Context, key string) ([]byte, error)
- func (c *RedisCache) GetJSON(ctx context.Context, key string, dest interface{}) error
- func (c *RedisCache) GetWithTTL(ctx context.Context, key string) ([]byte, time.Duration, error)
- func (c *RedisCache) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
- func (c *RedisCache) SetJSON(ctx context.Context, key string, value interface{}, expiration time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
Get(ctx context.Context, key string) ([]byte, error)
Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
Delete(ctx context.Context, key string) error
Exists(ctx context.Context, key string) (bool, error)
Clear(ctx context.Context) error
GetWithTTL(ctx context.Context, key string) ([]byte, time.Duration, error)
SetJSON(ctx context.Context, key string, value interface{}, expiration time.Duration) error
GetJSON(ctx context.Context, key string, dest interface{}) error
}
Cache interface defines caching operations
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
CacheManager manages multiple cache instances
func NewCacheManager ¶
func NewCacheManager() *CacheManager
NewCacheManager creates a new cache manager
func (*CacheManager) AddCache ¶
func (m *CacheManager) AddCache(name string, cache Cache)
AddCache adds a cache instance
func (*CacheManager) GetCache ¶
func (m *CacheManager) GetCache(name string) (Cache, error)
GetCache retrieves a cache instance
func (*CacheManager) GetDefaultCache ¶
func (m *CacheManager) GetDefaultCache() Cache
GetDefaultCache returns the default cache instance
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache implements an in-memory cache
func NewMemoryCache ¶
func NewMemoryCache(maxTTL time.Duration) *MemoryCache
NewMemoryCache creates a new in-memory cache
func (*MemoryCache) Clear ¶
func (c *MemoryCache) Clear(ctx context.Context) error
Clear removes all values from memory cache
func (*MemoryCache) Delete ¶
func (c *MemoryCache) Delete(ctx context.Context, key string) error
Delete removes a value from memory cache
func (*MemoryCache) GetJSON ¶
func (c *MemoryCache) GetJSON(ctx context.Context, key string, dest interface{}) error
GetJSON retrieves and decodes a JSON value
func (*MemoryCache) GetWithTTL ¶
GetWithTTL retrieves a value with remaining TTL
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache implements Redis-based cache
func NewRedisCache ¶
func NewRedisCache(addr, password string, db int, prefix string) *RedisCache
NewRedisCache creates a new Redis cache
func (*RedisCache) Clear ¶
func (c *RedisCache) Clear(ctx context.Context) error
Clear removes all values from Redis cache with the prefix
func (*RedisCache) Delete ¶
func (c *RedisCache) Delete(ctx context.Context, key string) error
Delete removes a value from Redis cache
func (*RedisCache) GetJSON ¶
func (c *RedisCache) GetJSON(ctx context.Context, key string, dest interface{}) error
GetJSON retrieves and decodes a JSON value from Redis
func (*RedisCache) GetWithTTL ¶
GetWithTTL retrieves a value with remaining TTL from Redis