feat: upgrade cache
This commit is contained in:
@ -12,28 +12,20 @@ import (
|
||||
)
|
||||
|
||||
// ResultParseFunc 结解析方法
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:18 2024/6/21
|
||||
type ResultParseFunc func(res string) error
|
||||
type ResultParseFunc func(res any) error
|
||||
|
||||
// ICache 缓存的接口约束
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:09 2024/6/21
|
||||
type ICache interface {
|
||||
// Exist 缓存是否存在
|
||||
Exist(ctx context.Context, cacheInstanceFlag string, key string) (bool, error)
|
||||
// TTL key还有多长时间过期
|
||||
TTL(ctx context.Context, cacheInstanceFlag string, key string) (int64, error)
|
||||
// Set 设置缓存
|
||||
Set(ctx context.Context, cacheInstanceFlag string, key string, value string, ttl int64) error
|
||||
Set(ctx context.Context, cacheInstanceFlag string, key string, value any, ttl int64) error
|
||||
// Get 读取原始缓存数据
|
||||
Get(ctx context.Context, cacheInstanceFlag string, key string) (string, error)
|
||||
Get(ctx context.Context, cacheInstanceFlag string, key string) (any, error)
|
||||
// GetWithParse 获取结果并解析
|
||||
GetWithParse(ctx context.Context, cacheInstanceFlag string, key string, parseFunc ResultParseFunc) (string, error)
|
||||
GetWithParse(ctx context.Context, cacheInstanceFlag string, key string, parseFunc ResultParseFunc) (any, error)
|
||||
// Delete 删除缓存
|
||||
Delete(ctx context.Context, cacheInstanceFlag string, key string) error
|
||||
}
|
||||
|
Reference in New Issue
Block a user