cache

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultExpiration = time.Hour
View Source
var (
	ErrNotExist = errors.New("cache does not exist")
)

Functions

func LocalClear

func LocalClear(key string)

func LocalGet

func LocalGet(key string) (any, bool)

func LocalRemember

func LocalRemember[T any](key string, ttl time.Duration, fn func() (T, error)) (T, error)

func LocalSet

func LocalSet(key string, val any, ttl time.Duration)

Types

type Cache

type Cache interface {
	Has(ctx context.Context, key string) (bool, error)
	Set(ctx context.Context, key string, value any, expiration time.Duration) error
	Get(ctx context.Context, key string) ([]byte, error)
	Forget(ctx context.Context, key string) error
	Remember(ctx context.Context, key string, ttl time.Duration, fn func() ([]byte, error)) ([]byte, error)
}

func NewRedis

func NewRedis(addr string, opts ...RedisOptionFunc) Cache

func NewRedisFromConfig

func NewRedisFromConfig(config config.Redis) Cache

type Redis

type Redis struct {
	// contains filtered or unexported fields
}

func (*Redis) Forget

func (r *Redis) Forget(ctx context.Context, key string) error

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string) ([]byte, error)

func (*Redis) Has

func (r *Redis) Has(ctx context.Context, key string) (bool, error)

func (*Redis) Remember

func (r *Redis) Remember(ctx context.Context, key string, ttl time.Duration, fn func() ([]byte, error)) ([]byte, error)

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, key string, value any, expiration time.Duration) error

func (*Redis) SetOption

func (r *Redis) SetOption(opt func(*redis.Options))

type RedisOptionFunc

type RedisOptionFunc func(*Redis)

func SetDB

func SetDB(db int) RedisOptionFunc

func SetPassword

func SetPassword(password string) RedisOptionFunc

func SetPrefix

func SetPrefix(prefix string) RedisOptionFunc

Jump to

Keyboard shortcuts

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