cache

package
v0.0.0-...-e8e2c10 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

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")

Functions

This section is empty.

Types

type CacheClient

type CacheClient struct {
	Client  *redis.Client
	Enabled bool
	// contains filtered or unexported fields
}

CacheClient redis cache client.

func NewCacheClient

func NewCacheClient(url string, enabled bool, log *zap.Logger) *CacheClient

NewCacheClient init a new 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.

type CacheGetFunc

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

type DummyCacheClient

type DummyCacheClient struct {
}

DummyCacheClient dummy cache client.

func NewDummyCacheClient

func NewDummyCacheClient() DummyCacheClient

NewDummyCacheClient create a new instance of DummyCacheClient

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

Jump to

Keyboard shortcuts

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