实现服务的缓存策略设置

This commit is contained in:
GoEdgeLab
2020-10-04 20:38:27 +08:00
parent db21a86825
commit 0bbd178b29
25 changed files with 502 additions and 133 deletions

View File

@@ -1,11 +1,12 @@
package cache
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
@@ -27,23 +28,7 @@ func (this *IndexAction) RunGet(params struct {
}
this.Data["webId"] = webConfig.Id
this.Data["cacheConfig"] = webConfig.CacheRefs
// 所有缓存策略
cachePoliciesResp, err := this.RPC().HTTPCachePolicyRPC().FindAllEnabledHTTPCachePolicies(this.AdminContext(), &pb.FindAllEnabledHTTPCachePoliciesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
policyMaps := []maps.Map{}
for _, policy := range cachePoliciesResp.CachePolicies {
policyMaps = append(policyMaps, maps.Map{
"id": policy.Id,
"name": policy.Name,
"isOn": policy.IsOn,
})
}
this.Data["policies"] = policyMaps
this.Data["cacheConfig"] = webConfig.Cache
this.Show()
}
@@ -55,10 +40,27 @@ func (this *IndexAction) RunPost(params struct {
Must *actions.Must
}) {
// TODO 校验配置
cacheConfig := &serverconfigs.HTTPCacheConfig{}
err := json.Unmarshal(params.CacheJSON, cacheConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
// 去除不必要的部分
for _, cacheRef := range cacheConfig.CacheRefs {
cacheRef.CachePolicy = nil
}
cacheJSON, err := json.Marshal(cacheConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
WebId: params.WebId,
CacheJSON: params.CacheJSON,
CacheJSON: cacheJSON,
})
if err != nil {
this.ErrorPage(err)