diff --git a/internal/db/models/http_cache_policy_dao.go b/internal/db/models/http_cache_policy_dao.go index 54c6d34d..75f05b1f 100644 --- a/internal/db/models/http_cache_policy_dao.go +++ b/internal/db/models/http_cache_policy_dao.go @@ -183,6 +183,12 @@ func (this *HTTPCachePolicyDAO) CreateDefaultCachePolicy(tx *dbs.Tx, name string var storageOptions = &serverconfigs.HTTPFileCacheStorage{ Dir: "/opt/cache", + MemoryPolicy: &serverconfigs.HTTPCachePolicy{ + Capacity: &shared.SizeCapacity{ + Count: 1, + Unit: shared.SizeCapacityUnitGB, + }, + }, } storageOptionsJSON, err := json.Marshal(storageOptions) if err != nil { @@ -303,7 +309,7 @@ func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64, c } // CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量 -func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, clusterId int64, keyword string) (int64, error) { +func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, clusterId int64, keyword string, storageType string) (int64, error) { query := this.Query(tx). State(HTTPCachePolicyStateEnabled) if clusterId > 0 { @@ -314,11 +320,14 @@ func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, clu query.Where("(name LIKE :keyword)"). Param("keyword", "%"+keyword+"%") } + if len(storageType) > 0 { + query.Attr("type", storageType) + } return query.Count() } // ListEnabledHTTPCachePolicies 列出单页的缓存策略 -func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, clusterId int64, keyword string, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) { +func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, clusterId int64, keyword string, storageType string, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) { query := this.Query(tx). State(HTTPCachePolicyStateEnabled) if clusterId > 0 { @@ -329,6 +338,9 @@ func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, cluster query.Where("(name LIKE :keyword)"). Param("keyword", "%"+keyword+"%") } + if len(storageType) > 0 { + query.Attr("type", storageType) + } ones, err := query. ResultPk(). Offset(offset). diff --git a/internal/rpc/services/service_http_cache_policy.go b/internal/rpc/services/service_http_cache_policy.go index 211a4010..f5de99ac 100644 --- a/internal/rpc/services/service_http_cache_policy.go +++ b/internal/rpc/services/service_http_cache_policy.go @@ -99,7 +99,7 @@ func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context tx := this.NullTx() - count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx, req.NodeClusterId, req.Keyword) + count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx, req.NodeClusterId, req.Keyword, req.Type) if err != nil { return nil, err } @@ -116,7 +116,7 @@ func (this *HTTPCachePolicyService) ListEnabledHTTPCachePolicies(ctx context.Con tx := this.NullTx() - cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.NodeClusterId, req.Keyword, req.Offset, req.Size) + cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.NodeClusterId, req.Keyword, req.Type, req.Offset, req.Size) if err != nil { return nil, err }