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

Method handleStatCache

internal/nodes/api_stream.go:260–297  ·  view source on GitHub ↗

统计缓存

(message *pb.NodeStreamMessage)

Source from the content-addressed store, hash-verified

258
259// 统计缓存
260func (this *APIStream) handleStatCache(message *pb.NodeStreamMessage) error {
261 msg := &messageconfigs.ReadCacheMessage{}
262 err := json.Unmarshal(message.DataJSON, msg)
263 if err != nil {
264 this.replyFail(message.RequestId, "decode message data failed: "+err.Error())
265 return err
266 }
267
268 storage, shouldStop, err := this.cacheStorage(message, msg.CachePolicyJSON)
269 if err != nil {
270 return err
271 }
272 if shouldStop {
273 defer func() {
274 storage.Stop()
275 }()
276 }
277
278 stat, err := storage.Stat()
279 if err != nil {
280 this.replyFail(message.RequestId, "stat failed: "+err.Error())
281 return err
282 }
283
284 sizeFormat := ""
285 if stat.Size < (1 << 10) {
286 sizeFormat = strconv.FormatInt(stat.Size, 10) + " Bytes"
287 } else if stat.Size < (1 << 20) {
288 sizeFormat = fmt.Sprintf("%.2f KiB", float64(stat.Size)/(1<<10))
289 } else if stat.Size < (1 << 30) {
290 sizeFormat = fmt.Sprintf("%.2f MiB", float64(stat.Size)/(1<<20))
291 } else {
292 sizeFormat = fmt.Sprintf("%.2f GiB", float64(stat.Size)/(1<<30))
293 }
294 this.replyOk(message.RequestId, "size:"+sizeFormat+", count:"+strconv.Itoa(stat.Count))
295
296 return nil
297}
298
299// 清理缓存
300func (this *APIStream) handleCleanCache(message *pb.NodeStreamMessage) error {

Callers 1

loopMethod · 0.95

Calls 6

replyFailMethod · 0.95
cacheStorageMethod · 0.95
replyOkMethod · 0.95
StopMethod · 0.65
StatMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected