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

Method cacheStorage

internal/nodes/api_stream.go:505–529  ·  view source on GitHub ↗

获取缓存存取对象

(message *pb.NodeStreamMessage, cachePolicyJSON []byte)

Source from the content-addressed store, hash-verified

503
504// 获取缓存存取对象
505func (this *APIStream) cacheStorage(message *pb.NodeStreamMessage, cachePolicyJSON []byte) (storage caches.StorageInterface, shouldStop bool, err error) {
506 cachePolicy := &serverconfigs.HTTPCachePolicy{}
507 err = json.Unmarshal(cachePolicyJSON, cachePolicy)
508 if err != nil {
509 this.replyFail(message.RequestId, "decode cache policy config failed: "+err.Error())
510 return nil, false, err
511 }
512
513 storage = caches.SharedManager.FindStorageWithPolicy(cachePolicy.Id)
514 if storage == nil {
515 storage = caches.SharedManager.NewStorageWithPolicy(cachePolicy)
516 if storage == nil {
517 this.replyFail(message.RequestId, "invalid storage type '"+cachePolicy.Type+"'")
518 return nil, false, errors.New("invalid storage type '" + cachePolicy.Type + "'")
519 }
520 err = storage.Init()
521 if err != nil {
522 this.replyFail(message.RequestId, "storage init failed: "+err.Error())
523 return nil, false, err
524 }
525 shouldStop = true
526 }
527
528 return
529}

Callers 4

handleWriteCacheMethod · 0.95
handleReadCacheMethod · 0.95
handleStatCacheMethod · 0.95
handleCleanCacheMethod · 0.95

Calls 6

replyFailMethod · 0.95
NewFunction · 0.92
FindStorageWithPolicyMethod · 0.80
NewStorageWithPolicyMethod · 0.80
InitMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected