@@ -37,12 +37,12 @@ func init() {
3737 })
3838}
3939
40- // 初始化
40+ // Init 初始化
4141func (this * HTTPCachePolicyDAO ) Init () {
4242 _ = this .DAOObject .Init ()
4343}
4444
45- // 启用条目
45+ // EnableHTTPCachePolicy 启用条目
4646func (this * HTTPCachePolicyDAO ) EnableHTTPCachePolicy (tx * dbs.Tx , id int64 ) error {
4747 _ , err := this .Query (tx ).
4848 Pk (id ).
@@ -51,7 +51,7 @@ func (this *HTTPCachePolicyDAO) EnableHTTPCachePolicy(tx *dbs.Tx, id int64) erro
5151 return err
5252}
5353
54- // 禁用条目
54+ // DisableHTTPCachePolicy 禁用条目
5555func (this * HTTPCachePolicyDAO ) DisableHTTPCachePolicy (tx * dbs.Tx , policyId int64 ) error {
5656 _ , err := this .Query (tx ).
5757 Pk (policyId ).
@@ -63,7 +63,7 @@ func (this *HTTPCachePolicyDAO) DisableHTTPCachePolicy(tx *dbs.Tx, policyId int6
6363 return this .NotifyUpdate (tx , policyId )
6464}
6565
66- // 查找启用中的条目
66+ // FindEnabledHTTPCachePolicy 查找启用中的条目
6767func (this * HTTPCachePolicyDAO ) FindEnabledHTTPCachePolicy (tx * dbs.Tx , id int64 ) (* HTTPCachePolicy , error ) {
6868 result , err := this .Query (tx ).
6969 Pk (id ).
@@ -75,15 +75,15 @@ func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicy(tx *dbs.Tx, id int64)
7575 return result .(* HTTPCachePolicy ), err
7676}
7777
78- // 根据主键查找名称
78+ // FindHTTPCachePolicyName 根据主键查找名称
7979func (this * HTTPCachePolicyDAO ) FindHTTPCachePolicyName (tx * dbs.Tx , id int64 ) (string , error ) {
8080 return this .Query (tx ).
8181 Pk (id ).
8282 Result ("name" ).
8383 FindStringCol ("" )
8484}
8585
86- // 查找所有可用的缓存策略
86+ // FindAllEnabledCachePolicies 查找所有可用的缓存策略
8787func (this * HTTPCachePolicyDAO ) FindAllEnabledCachePolicies (tx * dbs.Tx ) (result []* HTTPCachePolicy , err error ) {
8888 _ , err = this .Query (tx ).
8989 State (HTTPCachePolicyStateEnabled ).
@@ -93,7 +93,7 @@ func (this *HTTPCachePolicyDAO) FindAllEnabledCachePolicies(tx *dbs.Tx) (result
9393 return
9494}
9595
96- // 创建缓存策略
96+ // CreateCachePolicy 创建缓存策略
9797func (this * HTTPCachePolicyDAO ) CreateCachePolicy (tx * dbs.Tx , isOn bool , name string , description string , capacityJSON []byte , maxKeys int64 , maxSizeJSON []byte , storageType string , storageOptionsJSON []byte ) (int64 , error ) {
9898 op := NewHTTPCachePolicyOperator ()
9999 op .State = HTTPCachePolicyStateEnabled
@@ -118,7 +118,7 @@ func (this *HTTPCachePolicyDAO) CreateCachePolicy(tx *dbs.Tx, isOn bool, name st
118118 return types .Int64 (op .Id ), nil
119119}
120120
121- // 修改缓存策略
121+ // UpdateCachePolicy 修改缓存策略
122122func (this * HTTPCachePolicyDAO ) UpdateCachePolicy (tx * dbs.Tx , policyId int64 , isOn bool , name string , description string , capacityJSON []byte , maxKeys int64 , maxSizeJSON []byte , storageType string , storageOptionsJSON []byte ) error {
123123 if policyId <= 0 {
124124 return errors .New ("invalid policyId" )
@@ -147,7 +147,7 @@ func (this *HTTPCachePolicyDAO) UpdateCachePolicy(tx *dbs.Tx, policyId int64, is
147147 return this .NotifyUpdate (tx , policyId )
148148}
149149
150- // 组合配置
150+ // ComposeCachePolicy 组合配置
151151func (this * HTTPCachePolicyDAO ) ComposeCachePolicy (tx * dbs.Tx , policyId int64 ) (* serverconfigs.HTTPCachePolicy , error ) {
152152 policy , err := this .FindEnabledHTTPCachePolicy (tx , policyId )
153153 if err != nil {
@@ -196,17 +196,27 @@ func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64) (
196196 config .Options = m
197197 }
198198
199+ // refs
200+ if IsNotNull (policy .Refs ) {
201+ refs := []* serverconfigs.HTTPCacheRef {}
202+ err = json .Unmarshal ([]byte (policy .Refs ), & refs )
203+ if err != nil {
204+ return nil , err
205+ }
206+ config .CacheRefs = refs
207+ }
208+
199209 return config , nil
200210}
201211
202- // 计算可用缓存策略数量
212+ // CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量
203213func (this * HTTPCachePolicyDAO ) CountAllEnabledHTTPCachePolicies (tx * dbs.Tx ) (int64 , error ) {
204214 return this .Query (tx ).
205215 State (HTTPCachePolicyStateEnabled ).
206216 Count ()
207217}
208218
209- // 列出单页的缓存策略
219+ // ListEnabledHTTPCachePolicies 列出单页的缓存策略
210220func (this * HTTPCachePolicyDAO ) ListEnabledHTTPCachePolicies (tx * dbs.Tx , offset int64 , size int64 ) ([]* serverconfigs.HTTPCachePolicy , error ) {
211221 ones , err := this .Query (tx ).
212222 State (HTTPCachePolicyStateEnabled ).
@@ -237,7 +247,22 @@ func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, offset
237247 return cachePolicies , nil
238248}
239249
240- // 通知更新
250+ // UpdatePolicyRefs 设置默认的缓存条件
251+ func (this * HTTPCachePolicyDAO ) UpdatePolicyRefs (tx * dbs.Tx , policyId int64 , refsJSON []byte ) error {
252+ if len (refsJSON ) == 0 {
253+ return nil
254+ }
255+ err := this .Query (tx ).
256+ Pk (policyId ).
257+ Set ("refs" , refsJSON ).
258+ UpdateQuickly ()
259+ if err != nil {
260+ return err
261+ }
262+ return this .NotifyUpdate (tx , policyId )
263+ }
264+
265+ // NotifyUpdate 通知更新
241266func (this * HTTPCachePolicyDAO ) NotifyUpdate (tx * dbs.Tx , policyId int64 ) error {
242267 webIds , err := SharedHTTPWebDAO .FindAllWebIdsWithCachePolicyId (tx , policyId )
243268 if err != nil {
0 commit comments