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

1
go.mod
View File

@@ -19,7 +19,6 @@ require (
github.com/matoous/go-nanoid/v2 v2.1.0
github.com/mojocn/base64Captcha v1.3.8
github.com/mssola/useragent v1.0.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/penglongli/gin-metrics v0.1.13
github.com/pkg/sftp v1.13.9
github.com/prometheus-community/pro-bing v0.7.0

2
go.sum
View File

@@ -203,8 +203,6 @@ github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y=
github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0=
github.com/orcaman/concurrent-map/v2 v2.0.1 h1:jOJ5Pg2w1oeB6PeDurIYf6k9PQ+aTITr/6lP/L/zp6c=
github.com/orcaman/concurrent-map/v2 v2.0.1/go.mod h1:9Eq3TG2oBe5FirmYWQfYO5iH1q0Jv47PLaNK++uCdOM=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/penglongli/gin-metrics v0.1.13 h1:a1wyrXcbUVxL5w4c2TSv+9kyQA9qM1o23h0V6SdSHgQ=

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)
}