MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / handleReadCache

Method handleReadCache

internal/nodes/api_stream.go:223–257  ·  view source on GitHub ↗

读取缓存

(message *pb.NodeStreamMessage)

Source from the content-addressed store, hash-verified

221
222// 读取缓存
223func (this *APIStream) handleReadCache(message *pb.NodeStreamMessage) error {
224 msg := &messageconfigs.ReadCacheMessage{}
225 err := json.Unmarshal(message.DataJSON, msg)
226 if err != nil {
227 this.replyFail(message.RequestId, "decode message data failed: "+err.Error())
228 return err
229 }
230
231 storage, shouldStop, err := this.cacheStorage(message, msg.CachePolicyJSON)
232 if err != nil {
233 return err
234 }
235 if shouldStop {
236 defer func() {
237 storage.Stop()
238 }()
239 }
240
241 reader, err := storage.OpenReader(msg.Key, false, false)
242 if err != nil {
243 if err == caches.ErrNotFound {
244 this.replyFail(message.RequestId, "key not found")
245 return nil
246 }
247 this.replyFail(message.RequestId, "read key failed: "+err.Error())
248 return nil
249 }
250 defer func() {
251 _ = reader.Close()
252 }()
253
254 this.replyOk(message.RequestId, "value "+strconv.FormatInt(reader.BodySize(), 10)+" bytes")
255
256 return nil
257}
258
259// 统计缓存
260func (this *APIStream) handleStatCache(message *pb.NodeStreamMessage) error {

Callers 1

loopMethod · 0.95

Calls 8

replyFailMethod · 0.95
cacheStorageMethod · 0.95
replyOkMethod · 0.95
StopMethod · 0.65
OpenReaderMethod · 0.65
CloseMethod · 0.65
BodySizeMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected