获取缓存存取对象
(message *pb.NodeStreamMessage, cachePolicyJSON []byte)
| 503 | |
| 504 | // 获取缓存存取对象 |
| 505 | func (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 | } |
no test coverage detected