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

Method Put

internal/caches/open_file_cache.go:89–123  ·  view source on GitHub ↗
(filename string, file *OpenFile)

Source from the content-addressed store, hash-verified

87}
88
89func (this *OpenFileCache) Put(filename string, file *OpenFile) {
90 filename = filepath.Clean(filename)
91
92 if file.size > maxOpenFileSize {
93 return
94 }
95
96 this.locker.Lock()
97 defer this.locker.Unlock()
98
99 // 如果超过当前容量,则关闭最早的
100 if this.count >= this.maxCount || this.usedSize+file.size >= this.capacitySize {
101 this.consumeHead()
102 return
103 }
104
105 pool, ok := this.poolMap[filename]
106 var success bool
107 if ok {
108 success = pool.Put(file)
109 } else {
110 _ = this.watcher.Add(filename)
111 pool = NewOpenFilePool(filename)
112 pool.version = file.version
113 this.poolMap[filename] = pool
114 success = pool.Put(file)
115 }
116 this.poolList.Push(pool.linkItem)
117
118 // 检查长度
119 if success {
120 this.count++
121 this.usedSize += file.size
122 }
123}
124
125func (this *OpenFileCache) Close(filename string) {
126 filename = filepath.Clean(filename)

Callers 3

Calls 7

consumeHeadMethod · 0.95
NewOpenFilePoolFunction · 0.85
AddMethod · 0.65
CleanMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45
PushMethod · 0.45

Tested by 3