cachestore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 5 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.

- **CacheStorer Interface**: An interface for cache storage operations. It includes methods for setting, getting, and deleting cacheable entities.

- **RedisClient**: A concrete implementation of the CacheStorer 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 CacheStorer

type CacheStorer interface {
	Set(ctx context.Context, value Cacheable) error
	Get(ctx context.Context, key string, target Cacheable) error
	Delete(ctx context.Context, key string) error
}

CacheStorer 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 RedisClient

type RedisClient struct {
	Client *redis.Client
}

RedisClient is a Redis implementation of CacheStorer.

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