cachestore

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 6 Imported by: 0

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 Cacheable

type Cacheable interface {
	CacheKey() string
	CacheExpiration() time.Duration
}

Cacheable is an interface that all cacheable entities should implement.

type MockCacheStore added in v0.3.0

type MockCacheStore struct {
	mock.Mock
}

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

func (*MockCacheStore) Get added in v0.3.0

func (m *MockCacheStore) Get(ctx context.Context, key string, val Cacheable) error

func (*MockCacheStore) Set added in v0.3.0

func (m *MockCacheStore) Set(ctx context.Context, val Cacheable) 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.

func (*RedisClient) Get

func (rc *RedisClient) Get(ctx context.Context, key string, target Cacheable) error

Get retrieves a Cacheable entity from Redis.

func (*RedisClient) Set

func (rc *RedisClient) Set(ctx context.Context, value Cacheable) error

Set stores a Cacheable entity in Redis.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL