优化文件缓存

This commit is contained in:
GoEdgeLab
2021-06-13 17:37:57 +08:00
parent 117bcaaf0a
commit 468af65edd
11 changed files with 309 additions and 101 deletions

View File

@@ -92,8 +92,8 @@ func (this *MemoryList) Exist(hash string) (bool, error) {
return !item.IsExpired(), nil
}
// FindKeysWithPrefix 根据前缀进行查找
func (this *MemoryList) FindKeysWithPrefix(prefix string) (keys []string, err error) {
// CleanPrefix 根据前缀进行清除
func (this *MemoryList) CleanPrefix(prefix string) error {
this.locker.RLock()
defer this.locker.RUnlock()
@@ -101,11 +101,11 @@ func (this *MemoryList) FindKeysWithPrefix(prefix string) (keys []string, err er
for _, itemMap := range this.itemMaps {
for _, item := range itemMap {
if strings.HasPrefix(item.Key, prefix) {
keys = append(keys, item.Key)
item.ExpiredAt = 0
}
}
}
return
return nil
}
func (this *MemoryList) Remove(hash string) error {
@@ -225,6 +225,10 @@ func (this *MemoryList) OnRemove(f func(item *Item)) {
this.onRemove = f
}
func (this *MemoryList) Close() error {
return nil
}
func (this *MemoryList) print(t *testing.T) {
this.locker.Lock()
for _, itemMap := range this.itemMaps {