Files
waf-platform/EdgeNode/internal/caches/storage_file_plus.go
2026-02-04 20:27:13 +08:00

59 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package caches
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/mmap"
"os"
)
func (this *FileStorage) tryMMAPReader(isPartial bool, estimatedSize int64, path string) (Reader, error) {
// TODO 因为在实践中MMAP耗费了太多CPU在未解决之前先暂停支持
return nil, nil
var options = this.options // copy
if estimatedSize > 0 &&
!isPartial &&
(options != nil && options.EnableMMAP) &&
IsValidForMMAPSize(estimatedSize) {
var isOk bool
defer func() {
if !isOk {
_ = this.removeCacheFile(path)
}
}()
sharedMMAP, err := mmap.OpenSharedMMAP(path)
if err != nil {
if os.IsNotExist(err) {
isOk = true
return nil, ErrNotFound
}
return nil, err
}
reader, err := NewMMAPFileReader(sharedMMAP)
if err != nil {
if os.IsNotExist(err) {
isOk = true
return nil, ErrNotFound
}
return nil, err
}
err = reader.Init()
if err != nil {
if os.IsNotExist(err) {
isOk = true
return nil, ErrNotFound
}
return nil, err
}
isOk = true
return reader, nil
}
return nil, nil
}