cache

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPrefix 默认缓存前缀
	DefaultPrefix = "cache:"
	// DefaultExpireTime 默认过期时间
	DefaultExpireTime = time.Hour * 24
	// DefaultNotFoundExpireTime 结果为空时的过期时间 1分钟, 常用于数据为空时的缓存时间(缓存穿透)
	DefaultNotFoundExpireTime = time.Minute
	// NotFoundPlaceholder .
	NotFoundPlaceholder = "*"
)

Variables

View Source
var (
	// ErrPlaceholder 空数据标识
	ErrPlaceholder = errors.New("cache: placeholder")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(ctx context.Context, key string, val any, expiration time.Duration) error
	Get(ctx context.Context, key string, val any) error
	MultiSet(ctx context.Context, valMap map[string]any, expiration time.Duration) error
	MultiGet(ctx context.Context, keys []string, valueMap any, newObject func() any) error
	Del(ctx context.Context, keys ...string) error
	SetCacheWithNotFound(ctx context.Context, key string) error
}

Cache 定义cache驱动接口

func NewRedisCache

func NewRedisCache(client *redis.Client, opts ...Option) Cache

NewRedisCache new redis cache

type Option

type Option func(*Options)

func WithCodec

func WithCodec(codec codec.Encoding) Option

func WithExpire

func WithExpire(d time.Duration) Option

func WithPrefix

func WithPrefix(prefix string) Option

type Options

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

func NewOptions

func NewOptions(opt ...Option) Options

Jump to

Keyboard shortcuts

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