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

Method Close

internal/caches/writer_memory.go:114–158  ·  view source on GitHub ↗

Close 关闭

()

Source from the content-addressed store, hash-verified

112
113// Close 关闭
114func (this *MemoryWriter) Close() error {
115 // 需要在Locker之外
116 defer this.once.Do(func() {
117 this.endFunc(this.item)
118 })
119
120 if this.item == nil {
121 return nil
122 }
123
124 // check content length
125 if this.expectedBodySize > 0 && this.bodySize != this.expectedBodySize {
126 this.storage.locker.Lock()
127 delete(this.storage.valuesMap, this.hash)
128 this.storage.locker.Unlock()
129 return ErrUnexpectedContentLength
130 }
131
132 this.storage.locker.Lock()
133 this.item.IsDone = true
134 var err error
135 if this.isDirty {
136 if this.storage.parentStorage != nil {
137 this.storage.valuesMap[this.hash] = this.item
138
139 select {
140 case this.storage.dirtyChan <- types.String(this.bodySize) + "@" + this.key:
141 atomic.AddInt64(&this.storage.totalDirtySize, this.bodySize)
142 default:
143 // remove from values map
144 delete(this.storage.valuesMap, this.hash)
145
146 err = ErrWritingQueueFull
147 }
148 } else {
149 this.storage.valuesMap[this.hash] = this.item
150 }
151 } else {
152 this.storage.valuesMap[this.hash] = this.item
153 }
154
155 this.storage.locker.Unlock()
156
157 return err
158}
159
160// Discard 丢弃
161func (this *MemoryWriter) Discard() error {

Callers

nothing calls this directly

Calls 4

DoMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected