add 获取指定前缀的所有键
This commit is contained in:
12
lib/core/cache/lcoal.go
vendored
12
lib/core/cache/lcoal.go
vendored
@@ -1,6 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
@@ -24,6 +25,17 @@ func DeleteLocal(key string) {
|
|||||||
cNoExpiration.Delete(key)
|
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)
|
var cTTL = cache.New(6*time.Hour, 12*time.Hour)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user