cachex

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 10 Imported by: 0

README

CacheX

Go Go Report Card codecov GitHub

CacheX,一个go多级缓存组件

快速开始

go get github.com/kakkk/cachex@laltest

Documentation

Index

Constants

This section is empty.

Variables

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

ErrNotFound 回源查不到数据返回错误

Functions

This section is empty.

Types

type Builder

type Builder[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder[K comparable, V any](ctx context.Context) *Builder[K, V]

NewBuilder NewBuilder

func (*Builder[K, V]) AddCache

func (b *Builder[K, V]) AddCache(cache cache.Cache[V]) *Builder[K, V]

AddCache 添加多级缓存

func (*Builder[K, V]) Build

func (b *Builder[K, V]) Build() (*CacheX[K, V], error)

Build 设置并初始化缓存

func (*Builder[K, V]) SetAllowDowngrade

func (b *Builder[K, V]) SetAllowDowngrade(allow bool) *Builder[K, V]

SetAllowDowngrade 设置是否允许降级

func (*Builder[K, V]) SetDowngradeCacheExpireTime

func (b *Builder[K, V]) SetDowngradeCacheExpireTime(t time.Duration) *Builder[K, V]

SetDowngradeCacheExpireTime 设置降级最大业务过期时间

func (*Builder[K, V]) SetDowngradeCallBack

func (b *Builder[K, V]) SetDowngradeCallBack(cb DowngradeCallBack[K]) *Builder[K, V]

SetDowngradeCallBack 设置单个降级回调降级

func (*Builder[K, V]) SetGetDataKey

func (b *Builder[K, V]) SetGetDataKey(fn GetDataKey[K]) *Builder[K, V]

SetGetDataKey 设置获取DataKey函数

func (*Builder[K, V]) SetGetRealData

func (b *Builder[K, V]) SetGetRealData(fn GetRealData[K, V]) *Builder[K, V]

SetGetRealData 设置回源函数

func (*Builder[K, V]) SetHitCallback

func (b *Builder[K, V]) SetHitCallback(fn HitCallback) *Builder[K, V]

SetHitCallback 设置缓存命中回调

func (*Builder[K, V]) SetIsSetDefault added in v1.0.3

func (b *Builder[K, V]) SetIsSetDefault(isSetDefault bool) *Builder[K, V]

func (*Builder[K, V]) SetLogger

func (b *Builder[K, V]) SetLogger(logger Logger) *Builder[K, V]

SetLogger 设置Logger

func (*Builder[K, V]) SetMDowngradeCallBack

func (b *Builder[K, V]) SetMDowngradeCallBack(cb MDowngradeCallBack[K]) *Builder[K, V]

SetMDowngradeCallBack 设置批量降级回调降级

func (*Builder[K, V]) SetMGetRealData

func (b *Builder[K, V]) SetMGetRealData(fn MGetRealData[K, V]) *Builder[K, V]

SetMGetRealData 设置批量回源函数

func (*Builder[K, V]) SetMHitCallback

func (b *Builder[K, V]) SetMHitCallback(fn MHitCallback) *Builder[K, V]

SetMHitCallback 设置缓存批量命中回调

func (*Builder[K, V]) SetName

func (b *Builder[K, V]) SetName(name string) *Builder[K, V]

SetName 设置缓存名称

type CacheError

type CacheError interface {
	Error() string
	GetErrorByLevel(level int) error
	GetErrorLevels() map[int]bool
}

type CacheX

type CacheX[K comparable, V any] struct {
	// contains filtered or unexported fields
}

CacheX CacheX组件

func (*CacheX[K, V]) Delete

func (cx *CacheX[K, V]) Delete(ctx context.Context, key K) (err error)

Delete 删除缓存

func (*CacheX[K, V]) Get

func (cx *CacheX[K, V]) Get(ctx context.Context, key K, expire time.Duration) (data V, ok bool)

Get 查询缓存

func (*CacheX[K, V]) MDelete

func (cx *CacheX[K, V]) MDelete(ctx context.Context, keys []K) (err error)

Delete 批量删除缓存

func (*CacheX[K, V]) MGet

func (cx *CacheX[K, V]) MGet(ctx context.Context, keys []K, expire time.Duration) (data map[K]V)

MGet 批量查询缓存

func (*CacheX[K, V]) MSet

func (cx *CacheX[K, V]) MSet(ctx context.Context, kvs map[K]V) (err error)

MSet 批量设置缓存

func (*CacheX[K, V]) Ping added in v1.0.4

func (cx *CacheX[K, V]) Ping(ctx context.Context) ([]string, error)

func (*CacheX[K, V]) Set

func (cx *CacheX[K, V]) Set(ctx context.Context, key K, data V) (err error)

Set 设置缓存

type DowngradeCallBack

type DowngradeCallBack[K comparable] func(ctx context.Context, key K, err error)

DowngradeCallBack 降级回调函数

type GetDataKey

type GetDataKey[K comparable] func(key K) string

GetDataKey 获取数据Key函数

type GetRealData

type GetRealData[K comparable, V any] func(ctx context.Context, key K) (data V, err error)

GetRealData 回源函数

type HitCallback

type HitCallback func(name string, level int)

HitCallback 命中缓存回调函数

type Logger

type Logger interface {
	Debugf(ctx context.Context, format string, v ...any)
	Infof(ctx context.Context, format string, v ...any)
	Warnf(ctx context.Context, format string, v ...any)
	Errorf(ctx context.Context, format string, v ...any)
}

type MDowngradeCallBack

type MDowngradeCallBack[K comparable] func(ctx context.Context, keys []K, err error)

MDowngradeCallBack 批量降级回调函数

type MGetRealData

type MGetRealData[K comparable, V any] func(ctx context.Context, keys []K) (data map[K]V, err error)

MGetRealData 批量回源函数

type MHitCallback

type MHitCallback func(name string, level int, times int)

MHitCallback 批量命中缓存回调函数

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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