cache

package
v0.0.0-...-8ffcee5 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyConnected = errors.New("CACHE.ALREADY_CONNECTED.ERROR")
	ErrNotConnected     = errors.New("CACHE.NOT_CONNECTED.ERROR")
	ErrEntryNotFound    = errors.New("CACHE.ENTRY.NOT_FOUND.ERROR")
	ErrKeyEmpty         = errors.New("CACHE.KEY.EMPTY.ERROR")
)

Functions

func EncodeKey

func EncodeKey(keys ...string) string

func GetOrSet

func GetOrSet[T any](cache Cache, ctx context.Context, key string, ttl time.Duration, fn func() (*T, error)) (*T, error)

GetOrSet is a helper function that allow you get existing entry from the cache or set it if it does not exist yet the function must return a pointer of the expected type and an error

func Key

func Key(k string) (string, error)

func Marshal

func Marshal(v any) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, v any) error

Types

type Cache

type Cache interface {
	patterns.Connectable
	Get(ctx context.Context, key string, entry any) error
	Set(ctx context.Context, key string, entry any, ttl time.Duration) error
	Exist(ctx context.Context, key string) bool
	Del(ctx context.Context, key string) error
	Expire(ctx context.Context, key string, at time.Time) error
}

func New

func New(conf *config.Config) (Cache, error)

func NewNoop

func NewNoop() Cache

func NewRedis

func NewRedis(conf *config.Config) (Cache, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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