cache

package
v0.0.0-...-7b44a9b Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheNotFound = errors.New("cache not found")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, exp time.Duration) error
	Del(ctx context.Context, key string) error
}

func NewLocalCache

func NewLocalCache(max int) Cache

func NewRedisCache

func NewRedisCache(client redis.UniversalClient) Cache

func With

func With(cache Cache, options ...Option) Cache

type ObjectCache

type ObjectCache interface {
	Get(ctx context.Context, key string, dst any) error
	Set(ctx context.Context, key string, val any, exp time.Duration) error
	Del(ctx context.Context, key string) error
}

func JSONCache

func JSONCache(cache Cache) ObjectCache

func NewObjectCache

func NewObjectCache(cache Cache, marshal func(any) ([]byte, error), unmarshal func([]byte, any) error) ObjectCache

type Option

type Option func(o *cacheWithOptions)

func WithIgnoreNotFound

func WithIgnoreNotFound() Option

func WithPrefix

func WithPrefix(prefix string) Option

Jump to

Keyboard shortcuts

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