chore: 移除无用go-cache封装

This commit is contained in:
TsMask
2025-04-25 15:38:17 +08:00
parent be5fb5eb94
commit 4d4f6095f6
3 changed files with 0 additions and 59 deletions

View File

@@ -1,56 +0,0 @@
package cache
import (
"strings"
"time"
"github.com/patrickmn/go-cache"
)
// 创建一个全局的不过期缓存对象
var cNoExpiration = cache.New(cache.NoExpiration, cache.NoExpiration)
// 将数据放入缓存,并设置永不过期
func SetLocal(key string, value any) {
cNoExpiration.Set(key, value, cache.NoExpiration)
}
// 从缓存中获取数据
func GetLocal(key string) (any, bool) {
return cNoExpiration.Get(key)
}
// 从缓存中删除数据
func DeleteLocal(key string) {
cNoExpiration.Delete(key)
}
// 获取指定前缀的所有键
func GetLocalKeys(prefix string) []string {
prefix = strings.TrimSuffix(prefix, "*")
var keys []string
for key := range cNoExpiration.Items() {
if strings.HasPrefix(key, prefix) {
keys = append(keys, key)
}
}
return keys
}
// 创建一个全局的过期缓存对象
var cTTL = cache.New(6*time.Hour, 12*time.Hour)
// 设置具有过期时间的缓存项
func SetLocalTTL(key string, value any, expiration time.Duration) {
cTTL.Set(key, value, expiration)
}
// 从缓存中获取数据
func GetLocalTTL(key string) (any, bool) {
return cTTL.Get(key)
}
// 从缓存中删除数据
func DeleteLocalTTL(key string) {
cTTL.Delete(key)
}