cache

package
v0.0.0-...-bd521cb Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigCache

func BigCache(ctx context.Context, config bigcache.Config) (*bigcache.BigCache, error)

func SetClock

func SetClock(newClock clock.Clock) (oldClock clock.Clock)

func ToInt

func ToInt(v Value) int

func ToInt64

func ToInt64(v Value) int64

func ToStr

func ToStr(v Value) string

Types

type BatchLoaderFunc

type BatchLoaderFunc func(ctx context.Context, keys []string) (map[string]Value, error)

BatchLoaderFunc 加载多个 key 对应的 value,返回值字典里的 value **必须** 是指针类型

type BigCacheOption

type BigCacheOption func(context.Context, *bigCache)

func WithMetrics

func WithMetrics(logger *zerolog.Logger, name string) BigCacheOption

type Cache

type Cache interface {
	GetWithInfo(key string) (data []byte, expired bool, err error)
	Set(key string, value []byte) error
	Close() error
	Delete(keys ...string) error
}

func NewBigCache

func NewBigCache(ctx context.Context, cache *bigcache.BigCache, opts ...BigCacheOption) Cache

type Factory

type Factory func() Value

Factory 生成加载缓存内容的对象,**必须** 是指针类型

type LoaderFunc

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

LoaderFunc 加载 key 对应的 value,value **必须** 是指针类型

type LoadingCache

type LoadingCache interface {
	Get(ctx context.Context, key string) (Value, error)
	BatchGet(ctx context.Context, keys []string) (map[string]Value, error)
	Load(ctx context.Context, key string) (Value, error)
	BatchLoad(ctx context.Context, keys []string) (map[string]Value, error)
	Set(ctx context.Context, key string, value Value) error
	SetByData(ctx context.Context, key string, data []byte) error
	Delete(ctx context.Context, keys ...string) error
	Close(ctx context.Context) error
}

func NewLoading

func NewLoading(cache Cache, factory Factory, load LoaderFunc, opts ...LoadingCacheOption) LoadingCache

func NewNoOp

func NewNoOp(load LoaderFunc) LoadingCache

type LoadingCacheOption

type LoadingCacheOption func(*loadingCache)

func WithBatchLoader

func WithBatchLoader(batchLoad BatchLoaderFunc) LoadingCacheOption

func WithMarshalUnmarshal

func WithMarshalUnmarshal(marshal marshalFunc, unmarshal unmarshalFunc) LoadingCacheOption

func WithPostLoad

func WithPostLoad(postLoad PostLoad) LoadingCacheOption

type PostLoad

type PostLoad func(ctx context.Context, key string, data []byte) error

PostLoad 调用 LoaderFunc 获取值的时候

type Value

type Value interface {
	CacheKey() string
}

Value 为缓存对象,可反向生成缓存 Key

func Int64Value

func Int64Value(i int64) Value

func IntValue

func IntValue(i int) Value

func StrValue

func StrValue(a string) Value

Jump to

Keyboard shortcuts

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