[缓存]实现按照目录刷新缓存

This commit is contained in:
GoEdgeLab
2020-12-23 21:28:50 +08:00
parent 868ab9ed1b
commit 3c6ad87cb9
8 changed files with 66 additions and 7 deletions

View File

@@ -1,6 +1,9 @@
package caches
import "sync"
import (
"strings"
"sync"
)
// 缓存列表管理
type List struct {
@@ -43,6 +46,20 @@ func (this *List) Exist(hash string) bool {
return !item.IsExpired()
}
// 根据前缀进行查找
func (this *List) FindKeysWithPrefix(prefix string) (keys []string) {
this.locker.RLock()
defer this.locker.RUnlock()
// TODO 需要优化性能支持千万级数据低于1s的处理速度
for _, item := range this.m {
if strings.HasPrefix(item.Key, prefix) {
keys = append(keys, item.Key)
}
}
return
}
func (this *List) Remove(hash string) {
this.locker.Lock()