cache

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallFunc

func CallFunc(body CallFuncBody) (result []interface{}, err error)

CallFunc 利用反射动态执行函数, 直接从 batchExec 那边搬过来的

func Decode

func Decode(v []byte, target interface{}) error

Decode 将字节解析成对象

func Encode

func Encode(v interface{}) ([]byte, error)

Encode 进行 golang 的序列化

func GetFuncName

func GetFuncName(fc interface{}) string

GetFuncName 这里取函数最后的名字

Types

type CallFuncBody

type CallFuncBody struct {
	FuncName interface{} // 这里存放函数实体
	Params   []interface{}
	Result   []interface{}
	Err      error
	// contains filtered or unexported fields
}

CallFuncBody 调用函数的结构体

func (*CallFuncBody) GetCacheKey

func (cb *CallFuncBody) GetCacheKey() (key string, funcName string, err error)

func (*CallFuncBody) GetResult

func (cb *CallFuncBody) GetResult(returnItems ...interface{}) error

type CommonDrive

type CommonDrive interface {
	Save(k string, v interface{}, expire time.Duration) error
	Get(k string, target interface{}) error
	Delete(k string) bool
	Exist(k string) bool
	CacheFunc(funcName interface{}, params ...interface{}) *CallFuncBody
	DeleteFunc(funcName interface{}, params ...interface{}) bool
	SetExpire(k string, exp time.Duration) CommonDrive
	GetExpire(k string) time.Duration
	GetCacheFuncKey(funcName interface{}, params ...interface{}) (cacheKey string, err error)
	GetRedisClient() *redis.Client
}

CommonDrive 统一缓存驱动接口

func LoadRedisClient

func LoadRedisClient(c *redis.Client, defaultExpire ...time.Duration) CommonDrive

LoadRedisClient 获取 Redis 相关的缓存器

type RedisClient

type RedisClient struct {
	ExpireMap     sync.Map
	DefaultExpire time.Duration
	// contains filtered or unexported fields
}

func (*RedisClient) CacheFunc

func (c *RedisClient) CacheFunc(funcName interface{}, params ...interface{}) *CallFuncBody

CacheFunc 这里主要做的几件事, 1. 根据方法名和传参获取缓存, 注册返回值类型 key, 2. 查询是否存在对应 key 的缓存结果, 3. 返回缓存/返回执行结果

func (*RedisClient) Delete

func (c *RedisClient) Delete(k string) bool

func (*RedisClient) DeleteFunc added in v0.0.13

func (c *RedisClient) DeleteFunc(funcName interface{}, params ...interface{}) bool

DeleteFunc 删除对应的函数结果缓存

func (*RedisClient) Exist

func (c *RedisClient) Exist(k string) bool

func (*RedisClient) Get

func (c *RedisClient) Get(k string, target interface{}) error

func (*RedisClient) GetCacheFuncKey added in v0.0.15

func (c *RedisClient) GetCacheFuncKey(funcName interface{}, params ...interface{}) (cacheKey string, err error)

GetCacheFuncKey 返回对应的缓存 key

func (*RedisClient) GetExpire

func (c *RedisClient) GetExpire(k string) time.Duration

GetExpire 获取配置的缓存时长

func (*RedisClient) GetRedisClient added in v0.0.21

func (c *RedisClient) GetRedisClient() *redis.Client

GetRedisClient 获取当前客户端

func (*RedisClient) Save

func (c *RedisClient) Save(k string, v interface{}, expire time.Duration) error

func (*RedisClient) SetExpire

func (c *RedisClient) SetExpire(k string, expire time.Duration) CommonDrive

SetExpire 设置单个函数的缓存时长

Jump to

Keyboard shortcuts

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