mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-06 23:00:25 +08:00
实现缓存策略的部分功能
This commit is contained in:
38
internal/web/actions/default/servers/components/cache/cacheutils/utils.go
vendored
Normal file
38
internal/web/actions/default/servers/components/cache/cacheutils/utils.go
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package cacheutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
// 查找缓存策略名称并忽略错误
|
||||
func FindCachePolicyNameWithoutError(parent *actionutils.ParentAction, cachePolicyId int64) string {
|
||||
policy, err := FindCachePolicy(parent, cachePolicyId)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if policy == nil {
|
||||
return ""
|
||||
}
|
||||
return policy.Name
|
||||
}
|
||||
|
||||
// 查找缓存策略配置
|
||||
func FindCachePolicy(parent *actionutils.ParentAction, cachePolicyId int64) (*serverconfigs.HTTPCachePolicy, error) {
|
||||
resp, err := parent.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(parent.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: cachePolicyId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(resp.CachePolicyJSON) == 0 {
|
||||
return nil, errors.New("cache policy not found")
|
||||
}
|
||||
config := &serverconfigs.HTTPCachePolicy{}
|
||||
err = json.Unmarshal(resp.CachePolicyJSON, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
Reference in New Issue
Block a user