mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-16 10:00:26 +08:00
优化文件句柄缓存相关代码
This commit is contained in:
@@ -64,6 +64,8 @@ func NewOpenFileCache(maxCount int) (*OpenFileCache, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *OpenFileCache) Get(filename string) *OpenFile {
|
func (this *OpenFileCache) Get(filename string) *OpenFile {
|
||||||
|
filename = filepath.Clean(filename)
|
||||||
|
|
||||||
this.locker.RLock()
|
this.locker.RLock()
|
||||||
pool, ok := this.poolMap[filename]
|
pool, ok := this.poolMap[filename]
|
||||||
this.locker.RUnlock()
|
this.locker.RUnlock()
|
||||||
@@ -85,6 +87,8 @@ func (this *OpenFileCache) Get(filename string) *OpenFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *OpenFileCache) Put(filename string, file *OpenFile) {
|
func (this *OpenFileCache) Put(filename string, file *OpenFile) {
|
||||||
|
filename = filepath.Clean(filename)
|
||||||
|
|
||||||
if file.size > maxOpenFileSize {
|
if file.size > maxOpenFileSize {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -119,6 +123,8 @@ func (this *OpenFileCache) Put(filename string, file *OpenFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *OpenFileCache) Close(filename string) {
|
func (this *OpenFileCache) Close(filename string) {
|
||||||
|
filename = filepath.Clean(filename)
|
||||||
|
|
||||||
this.locker.Lock()
|
this.locker.Lock()
|
||||||
|
|
||||||
pool, ok := this.poolMap[filename]
|
pool, ok := this.poolMap[filename]
|
||||||
|
|||||||
@@ -622,6 +622,11 @@ func (this *FileStorage) openWriter(key string, expiredAt int64, status int, hea
|
|||||||
return nil, fmt.Errorf("%w (003)", ErrFileIsWriting)
|
return nil, fmt.Errorf("%w (003)", ErrFileIsWriting)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭
|
||||||
|
if openFileCache != nil {
|
||||||
|
openFileCache.Close(cachePath)
|
||||||
|
}
|
||||||
|
|
||||||
var metaBodySize int64 = -1
|
var metaBodySize int64 = -1
|
||||||
var metaHeaderSize = -1
|
var metaHeaderSize = -1
|
||||||
if isNewCreated {
|
if isNewCreated {
|
||||||
|
|||||||
Reference in New Issue
Block a user