Skip to content

Commit 6b2a015

Browse files
committed
创建缓存策略时默认加入缓存条件
1 parent 9e74baf commit 6b2a015

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

internal/db/models/http_cache_policy_dao.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,44 @@ func (this *HTTPCachePolicyDAO) CreateCachePolicy(tx *dbs.Tx, isOn bool, name st
111111
if len(storageOptionsJSON) > 0 {
112112
op.Options = storageOptionsJSON
113113
}
114-
err := this.Save(tx, op)
114+
115+
// 默认的缓存条件
116+
cacheRef := &serverconfigs.HTTPCacheRef{
117+
IsOn: true,
118+
Key: "${scheme}://${host}${requestURI}",
119+
Life: &shared.TimeDuration{Count: 2, Unit: shared.TimeDurationUnitHour},
120+
Status: []int{200},
121+
MaxSize: &shared.SizeCapacity{Count: 32, Unit: shared.SizeCapacityUnitMB},
122+
SkipResponseSetCookie: true,
123+
AllowChunkedEncoding: true,
124+
Conds: &shared.HTTPRequestCondsConfig{
125+
IsOn: true,
126+
Connector: "or",
127+
Groups: []*shared.HTTPRequestCondGroup{
128+
{
129+
IsOn: true,
130+
Connector: "or",
131+
Conds: []*shared.HTTPRequestCond{
132+
{
133+
Type: "url-extension",
134+
IsRequest: true,
135+
Param: "${requestPathExtension}",
136+
Operator: shared.RequestCondOperatorIn,
137+
Value: `[".html", ".js", ".css", ".gif", ".png", ".bmp", ".jpeg", ".jpg", ".webp", ".ico", ".pdf", ".ttf", ".eot", ".tiff", ".svg", ".svgz", ".eps", ".woff", ".otf", ".woff2", ".tif", ".csv", ".xls", ".xlsx", ".doc", ".docx", ".ppt", ".pptx", ".wav", ".mp3", ".mp4", ".ogg", ".mid", ".midi"]`,
138+
},
139+
},
140+
Description: "初始化规则",
141+
},
142+
},
143+
},
144+
}
145+
refsJSON, err := json.Marshal([]*serverconfigs.HTTPCacheRef{cacheRef})
146+
if err != nil {
147+
return 0, err
148+
}
149+
op.Refs = refsJSON
150+
151+
err = this.Save(tx, op)
115152
if err != nil {
116153
return 0, err
117154
}

0 commit comments

Comments
 (0)