mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-10 20:50:25 +08:00
优化缓存相关代码
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user