2024-06-21 14:02:50 +08:00
|
|
|
// Package cache ...
|
|
|
|
//
|
|
|
|
// Description : cache ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2023-03-21 12:09
|
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ResultParseFunc 结解析方法
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 11:18 2024/6/21
|
|
|
|
type ResultParseFunc func(res string) 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)
|
2024-10-09 18:30:12 +08:00
|
|
|
// TTL key还有多长时间过期
|
|
|
|
TTL(ctx context.Context, cacheInstanceFlag string, key string) (int64, error)
|
2024-06-21 14:02:50 +08:00
|
|
|
// Set 设置缓存
|
|
|
|
Set(ctx context.Context, cacheInstanceFlag string, key string, value string, ttl int64) error
|
|
|
|
// Get 读取原始缓存数据
|
|
|
|
Get(ctx context.Context, cacheInstanceFlag string, key string) (string, error)
|
|
|
|
// GetWithParse 获取结果并解析
|
|
|
|
GetWithParse(ctx context.Context, cacheInstanceFlag string, key string, parseFunc ResultParseFunc) (string, error)
|
|
|
|
// Delete 删除缓存
|
|
|
|
Delete(ctx context.Context, cacheInstanceFlag string, key string) error
|
|
|
|
}
|