优化缓存相关代码

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,6 +31,7 @@ func (this *OpenFilePool) Filename() string {
func (this *OpenFilePool) Get() (*OpenFile, bool) {
select {
case file := <-this.c:
if file != nil {
err := file.SeekStart()
if err != nil {
_ = file.Close()
@@ -39,6 +40,8 @@ func (this *OpenFilePool) Get() (*OpenFile, bool) {
file.version = this.version
return file, true
}
return nil, false
default:
return nil, false
}

View File

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