cache

package
v0.0.0-...-efbd42f Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Overview

Package cache implement a simple cache redis client. It define a type Cache that represent the cache client and It define the methods Get to get a valur from a cache key.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheNotEnabled = errors.New("CACHE NOT ENABLED")
	ErrNotFound        = errors.New("KEY NOT FOUND IN CACHE")
	ErrInternal        = errors.New("INTERNAL CACHE ERROR")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	CacheReadable
	CacheWriteable
}

Cache is the interface for cache client.

type CacheClient

type CacheClient struct {
	Client  *redis.Client
	Enabled bool

	Prefix string
	// contains filtered or unexported fields
}

CacheClient redis cache client.

func NewCacheClient

func NewCacheClient(redisClient *redis.Client, enabled bool, prefix string, log *zap.Logger) (*CacheClient, error)

NewCacheClient init a new cache client.

func (*CacheClient) Close

func (c *CacheClient) Close() error

Close close the cache client.

func (*CacheClient) Get

func (c *CacheClient) Get(ctx context.Context, key string) (string, error)

Get get a cache value or error from a key. If the cache is not enabled, the error value If the cache not contain a value from a key, the error value errors.ErrNotFound is returned. If exist some internal error in the cache, the error value errros.ErrInternalError is returned.

func (*CacheClient) Set

func (c *CacheClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set set a value in cache.

type CacheGetFunc

type CacheGetFunc func(ctx context.Context, key string) (string, error)

type CacheReadable

type CacheReadable interface {
	Get(ctx context.Context, key string) (string, error)
	Close() error
}

CacheReadable is the interface for read cache.

type CacheWriteable

type CacheWriteable interface {
	Set(ctx context.Context, key string, value interface{}, expirations time.Duration) error
}

CacheWriteable is the interface for write cache.

type DummyCacheClient

type DummyCacheClient struct {
}

DummyCacheClient dummy cache client.

func NewDummyCacheClient

func NewDummyCacheClient() *DummyCacheClient

NewDummyCacheClient create a new instance of DummyCacheClient

func (*DummyCacheClient) Close

func (d *DummyCacheClient) Close() error

Close dummy cache client.

func (*DummyCacheClient) Get

func (d *DummyCacheClient) Get(ctx context.Context, key string) (string, error)

Get get method is a dummy method that always does not find the cache. Use this Get function when run development enviroment

func (*DummyCacheClient) Set

func (d *DummyCacheClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set set method is a dummy method that always does not set the cache.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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