Documentation
¶
Index ¶
- Variables
- type Cache
- func (c *Cache) Client() *redis.Client
- func (c *Cache) Close() error
- func (c *Cache) Decr(ctx context.Context, key string) (int64, error)
- func (c *Cache) Delete(ctx context.Context, key string) error
- func (c *Cache) DeletePattern(ctx context.Context, pattern string) (int64, error)
- func (c *Cache) Exists(ctx context.Context, key string) (bool, error)
- func (c *Cache) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (c *Cache) Get(ctx context.Context, key string) (string, error)
- func (c *Cache) GetJSON(ctx context.Context, key string, dest interface{}) error
- func (c *Cache) HealthCheck(ctx context.Context) error
- func (c *Cache) Incr(ctx context.Context, key string) (int64, error)
- func (c *Cache) Ping(ctx context.Context) error
- func (c *Cache) Set(ctx context.Context, key string, value string, ttl time.Duration) error
- func (c *Cache) SetJSON(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (c *Cache) SetNX(ctx context.Context, key string, value string, ttl time.Duration) (bool, error)
- func (c *Cache) SetPrefix(prefix string)
- func (c *Cache) SortedSetAdd(ctx context.Context, key string, member string, score float64) error
- func (c *Cache) SortedSetRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (c *Cache) SortedSetRemove(ctx context.Context, key string, members ...interface{}) error
- func (c *Cache) TTL(ctx context.Context, key string) (time.Duration, error)
- type CacheWarmer
- type Config
- type InvalidateAll
- type InvalidateByTags
- type InvalidationStrategy
- type TagBasedCache
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyNotFound = errors.New("key not found") ErrInvalidTTL = errors.New("invalid TTL") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides Redis caching functionality.
func NewFromClient ¶
NewFromClient creates a cache from an existing Redis client.
func (*Cache) DeletePattern ¶
DeletePattern deletes all keys matching a pattern.
func (*Cache) HealthCheck ¶
HealthCheck returns cache health status.
func (*Cache) SetJSON ¶
func (c *Cache) SetJSON(ctx context.Context, key string, value interface{}, ttl time.Duration) error
SetJSON marshals and stores JSON.
func (*Cache) SetNX ¶
func (c *Cache) SetNX(ctx context.Context, key string, value string, ttl time.Duration) (bool, error)
SetNX stores a value only if key doesn't exist.
func (*Cache) SortedSetAdd ¶
SortedSetAdd adds to a sorted set.
func (*Cache) SortedSetRange ¶
func (c *Cache) SortedSetRange(ctx context.Context, key string, start, stop int64) ([]string, error)
SortedSetRange retrieves sorted set members by rank.
func (*Cache) SortedSetRemove ¶
SortedSetRemove removes from a sorted set.
type CacheWarmer ¶
type CacheWarmer struct {
// contains filtered or unexported fields
}
CacheWarmer preloads frequently accessed data into cache.
func NewCacheWarmer ¶
func NewCacheWarmer(cache *Cache, fetcher func(ctx context.Context, key string) (string, time.Duration, error)) *CacheWarmer
NewCacheWarmer creates a new cache warmer.
func (*CacheWarmer) WarmByPattern ¶
func (w *CacheWarmer) WarmByPattern(ctx context.Context, pattern string, fetchKeys func(ctx context.Context) ([]string, error)) error
WarmByPattern loads keys matching a pattern.
type Config ¶
type Config struct {
Addr string `default:"localhost:6379"`
Password string `default:""`
DB int `default:"0"`
PoolSize int `default:"10"`
MinIdleConns int `default:"5"`
DialTimeout time.Duration `default:"5s"`
ReadTimeout time.Duration `default:"3s"`
WriteTimeout time.Duration `default:"3s"`
}
Config holds Redis cache configuration.
type InvalidateAll ¶
type InvalidateAll struct {
// contains filtered or unexported fields
}
InvalidateAll removes all matching keys.
func NewInvalidateAll ¶
func NewInvalidateAll(prefix string) *InvalidateAll
NewInvalidateAll creates a strategy that deletes keys matching a prefix.
func (*InvalidateAll) Invalidate ¶
type InvalidateByTags ¶
type InvalidateByTags struct {
// contains filtered or unexported fields
}
InvalidateByTags invalidates keys by tags.
func NewInvalidateByTags ¶
func NewInvalidateByTags() *InvalidateByTags
NewInvalidateByTags creates a tag-based invalidation strategy.
func (*InvalidateByTags) Invalidate ¶
type InvalidationStrategy ¶
type InvalidationStrategy interface {
Invalidate(ctx context.Context, cache *Cache, keys ...string) error
}
InvalidationStrategy defines cache invalidation behavior.
type TagBasedCache ¶
type TagBasedCache struct {
// contains filtered or unexported fields
}
TagBasedCache adds tags to cached items for targeted invalidation.
func NewTagBasedCache ¶
func NewTagBasedCache(cache *Cache) *TagBasedCache
NewTagBasedCache creates a cache with tag support.
func (*TagBasedCache) InvalidateByTag ¶
func (t *TagBasedCache) InvalidateByTag(ctx context.Context, tag string) error
InvalidateByTag removes all cached items with a specific tag.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapter provides hexagonal architecture adapters for the cache package.
|
Package adapter provides hexagonal architecture adapters for the cache package. |
|
Package service provides application services for cache domain.
|
Package service provides application services for cache domain. |