缓存策略可以使用存储类型筛选

This commit is contained in:
GoEdgeLab
2022-03-14 15:42:48 +08:00
parent 6533d39379
commit 074b98de24
2 changed files with 16 additions and 4 deletions

View File

@@ -183,6 +183,12 @@ func (this *HTTPCachePolicyDAO) CreateDefaultCachePolicy(tx *dbs.Tx, name string
var storageOptions = &serverconfigs.HTTPFileCacheStorage{ var storageOptions = &serverconfigs.HTTPFileCacheStorage{
Dir: "/opt/cache", Dir: "/opt/cache",
MemoryPolicy: &serverconfigs.HTTPCachePolicy{
Capacity: &shared.SizeCapacity{
Count: 1,
Unit: shared.SizeCapacityUnitGB,
},
},
} }
storageOptionsJSON, err := json.Marshal(storageOptions) storageOptionsJSON, err := json.Marshal(storageOptions)
if err != nil { if err != nil {
@@ -303,7 +309,7 @@ func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64, c
} }
// CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量 // 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). query := this.Query(tx).
State(HTTPCachePolicyStateEnabled) State(HTTPCachePolicyStateEnabled)
if clusterId > 0 { if clusterId > 0 {
@@ -314,11 +320,14 @@ func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, clu
query.Where("(name LIKE :keyword)"). query.Where("(name LIKE :keyword)").
Param("keyword", "%"+keyword+"%") Param("keyword", "%"+keyword+"%")
} }
if len(storageType) > 0 {
query.Attr("type", storageType)
}
return query.Count() return query.Count()
} }
// ListEnabledHTTPCachePolicies 列出单页的缓存策略 // 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). query := this.Query(tx).
State(HTTPCachePolicyStateEnabled) State(HTTPCachePolicyStateEnabled)
if clusterId > 0 { if clusterId > 0 {
@@ -329,6 +338,9 @@ func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, cluster
query.Where("(name LIKE :keyword)"). query.Where("(name LIKE :keyword)").
Param("keyword", "%"+keyword+"%") Param("keyword", "%"+keyword+"%")
} }
if len(storageType) > 0 {
query.Attr("type", storageType)
}
ones, err := query. ones, err := query.
ResultPk(). ResultPk().
Offset(offset). Offset(offset).

View File

@@ -99,7 +99,7 @@ func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context
tx := this.NullTx() 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 { if err != nil {
return nil, err return nil, err
} }
@@ -116,7 +116,7 @@ func (this *HTTPCachePolicyService) ListEnabledHTTPCachePolicies(ctx context.Con
tx := this.NullTx() 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 { if err != nil {
return nil, err return nil, err
} }