2025-05-07 12:09:17 +08:00

37 lines
1.1 KiB
Go

// Package cache ...
//
// Description : cache ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-06-03 15:49
package cache
import (
"git.zhangdeman.cn/zhangdeman/network/httpclient/define"
)
// ICache 缓存定义
type ICache interface {
// Enable 是否启用缓存(总开关)
Enable() bool
// CacheTime 缓存时长, 单位 : s , 默认 1800, 最小值 90, 设置失效时间, 会上下波动60s, 避免缓存集中失效
CacheTime() int64
// IsAllow 针对当前请求数据和状态, 是否允许缓存
IsAllow(reqCfg *define.Request, response *define.Response) bool
// GetKey 获取缓存key
GetKey(reqCfg *define.Request) string
// GetValue 获取缓存值
GetValue(cacheKey string) string
// SetValue 设置缓存
SetValue(cacheKey string, cacheValue string) error
// TTL 缓存剩余生命周期(单位: s)
TTL(cacheKey string) int64
// PreHeatConfig 缓存预热配置
PreHeatConfig() *define.CachePreHeatConfig
// Lock 设置缓存时加锁
Lock(lockKey string) error
// Unlock 完成缓存设置时, 释放锁
Unlock(lockKey string) error
}