Documentation ¶
Overview ¶
Package cachestore provides a caching mechanism using Redis as the storage backend.
This package defines interfaces and implementations for storing, retrieving, and deleting cacheable entities in Redis.
The core components of this package include:
- **Cacheable Interface**: An interface that should be implemented by all entities that are intended to be cached. It provides methods for getting the cache key and expiration duration.
- **CacheStore Interface**: An interface for cache storage operations. It includes methods for setting, getting, and deleting cacheable entities.
- **RedisClient**: A concrete implementation of the CacheStore interface using Redis. It provides methods to interact with Redis to store, retrieve, and delete cacheable entities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheStore ¶ added in v0.3.0
type CacheStore interface { Set(ctx context.Context, value Cacheable) error Get(ctx context.Context, key string, target Cacheable) error Delete(ctx context.Context, key string) error }
CacheStore is the interface for cache storage.
type MockCacheStore ¶ added in v0.3.0
MockCacheStore mocks the CacheStorer interface for testing purposes.
func (*MockCacheStore) Delete ¶ added in v0.3.0
func (m *MockCacheStore) Delete(ctx context.Context, key string) error
type RedisClient ¶
type RedisClient struct {
Client *redis.Client
}
RedisClient is a Redis implementation of CacheStore.
func NewRedisClient ¶
func NewRedisClient(client *redis.Client) *RedisClient
NewRedisClient creates a new RedisClient with the given redis.Client.
func (*RedisClient) Delete ¶
func (rc *RedisClient) Delete(ctx context.Context, key string) error
Delete removes a value from Redis by key.