add 获取指定前缀的所有键

This commit is contained in:
TsMask
2023-09-05 19:04:08 +08:00
parent 8edc9f4cc3
commit 2ab01037d8

View File

@@ -1,6 +1,7 @@
package cache
import (
"strings"
"time"
"github.com/patrickmn/go-cache"
@@ -24,6 +25,17 @@ func DeleteLocal(key string) {
cNoExpiration.Delete(key)
}
// 获取指定前缀的所有键
func GetLocalKeys(prefix string) []string {
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)