MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / NewOpenFileCache

Function NewOpenFileCache

internal/caches/open_file_cache.go:37–64  ·  view source on GitHub ↗
(maxCount int)

Source from the content-addressed store, hash-verified

35}
36
37func NewOpenFileCache(maxCount int) (*OpenFileCache, error) {
38 if maxCount <= 0 {
39 maxCount = 16384
40 }
41
42 var cache = &OpenFileCache{
43 maxCount: maxCount,
44 poolMap: map[string]*OpenFilePool{},
45 poolList: linkedlist.NewList[*OpenFilePool](),
46 capacitySize: (int64(memutils.SystemMemoryGB()) << 30) / 16,
47 }
48
49 watcher, err := fsnotify.NewWatcher()
50 if err != nil {
51 return nil, err
52 }
53 cache.watcher = watcher
54
55 goman.New(func() {
56 for event := range watcher.Events {
57 if runtime.GOOS == "linux" || event.Op&fsnotify.Chmod != fsnotify.Chmod {
58 cache.Close(event.Name)
59 }
60 }
61 })
62
63 return cache, nil
64}
65
66func (this *OpenFileCache) Get(filename string) *OpenFile {
67 filename = filepath.Clean(filename)

Callers 4

initOpenFileCacheMethod · 0.85

Calls 2

NewFunction · 0.92
CloseMethod · 0.65

Tested by 3