From 4d4f6095f6a8a60714d863d6952e19856adfa16a Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Fri, 25 Apr 2025 15:38:17 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8go?= =?UTF-8?q?-cache=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 - go.sum | 2 -- lib/core/cache/lcoal.go | 56 ----------------------------------------- 3 files changed, 59 deletions(-) delete mode 100644 lib/core/cache/lcoal.go diff --git a/go.mod b/go.mod index 79e43e6e..373d24b3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 789d04eb..47e3fb30 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/lib/core/cache/lcoal.go b/lib/core/cache/lcoal.go deleted file mode 100644 index f6f12af0..00000000 --- a/lib/core/cache/lcoal.go +++ /dev/null @@ -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) -}