优化缓存相关代码

This commit is contained in:
GoEdgeLab
2022-12-05 10:46:44 +08:00
parent 194c953364
commit b36d70587d
2 changed files with 10 additions and 16 deletions

View File

@@ -31,14 +31,17 @@ func (this *OpenFilePool) Filename() string {
func (this *OpenFilePool) Get() (*OpenFile, bool) { func (this *OpenFilePool) Get() (*OpenFile, bool) {
select { select {
case file := <-this.c: case file := <-this.c:
err := file.SeekStart() if file != nil {
if err != nil { err := file.SeekStart()
_ = file.Close() if err != nil {
return nil, true _ = file.Close()
} return nil, true
file.version = this.version }
file.version = this.version
return file, true return file, true
}
return nil, false
default: default:
return nil, false return nil, false
} }

View File

@@ -710,9 +710,6 @@ func (this *FileStorage) Delete(key string) error {
return nil return nil
} }
this.locker.Lock()
defer this.locker.Unlock()
// 先尝试内存缓存 // 先尝试内存缓存
this.runMemoryStorageSafety(func(memoryStorage *MemoryStorage) { this.runMemoryStorageSafety(func(memoryStorage *MemoryStorage) {
_ = memoryStorage.Delete(key) _ = memoryStorage.Delete(key)
@@ -733,9 +730,6 @@ func (this *FileStorage) Delete(key string) error {
// Stat 统计 // Stat 统计
func (this *FileStorage) Stat() (*Stat, error) { func (this *FileStorage) Stat() (*Stat, error) {
this.locker.RLock()
defer this.locker.RUnlock()
return this.list.Stat(func(hash string) bool { return this.list.Stat(func(hash string) bool {
return true return true
}) })
@@ -834,9 +828,6 @@ func (this *FileStorage) Purge(keys []string, urlType string) error {
return nil return nil
} }
this.locker.Lock()
defer this.locker.Unlock()
// 先尝试内存缓存 // 先尝试内存缓存
this.runMemoryStorageSafety(func(memoryStorage *MemoryStorage) { this.runMemoryStorageSafety(func(memoryStorage *MemoryStorage) {
_ = memoryStorage.Purge(keys, urlType) _ = memoryStorage.Purge(keys, urlType)