From 9b00c0fe32802ffcb3189bceafa225b65533072d Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 10 Jun 2021 10:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=BC=93=E5=AD=98=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E6=97=B6=E9=BB=98=E8=AE=A4=E5=8A=A0=E5=85=A5=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/http_cache_policy_dao.go | 39 ++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/internal/db/models/http_cache_policy_dao.go b/internal/db/models/http_cache_policy_dao.go index 55be7e2e..62ca2819 100644 --- a/internal/db/models/http_cache_policy_dao.go +++ b/internal/db/models/http_cache_policy_dao.go @@ -111,7 +111,44 @@ func (this *HTTPCachePolicyDAO) CreateCachePolicy(tx *dbs.Tx, isOn bool, name st if len(storageOptionsJSON) > 0 { op.Options = storageOptionsJSON } - err := this.Save(tx, op) + + // 默认的缓存条件 + cacheRef := &serverconfigs.HTTPCacheRef{ + IsOn: true, + Key: "${scheme}://${host}${requestURI}", + Life: &shared.TimeDuration{Count: 2, Unit: shared.TimeDurationUnitHour}, + Status: []int{200}, + MaxSize: &shared.SizeCapacity{Count: 32, Unit: shared.SizeCapacityUnitMB}, + SkipResponseSetCookie: true, + AllowChunkedEncoding: true, + Conds: &shared.HTTPRequestCondsConfig{ + IsOn: true, + Connector: "or", + Groups: []*shared.HTTPRequestCondGroup{ + { + IsOn: true, + Connector: "or", + Conds: []*shared.HTTPRequestCond{ + { + Type: "url-extension", + IsRequest: true, + Param: "${requestPathExtension}", + Operator: shared.RequestCondOperatorIn, + 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"]`, + }, + }, + Description: "初始化规则", + }, + }, + }, + } + refsJSON, err := json.Marshal([]*serverconfigs.HTTPCacheRef{cacheRef}) + if err != nil { + return 0, err + } + op.Refs = refsJSON + + err = this.Save(tx, op) if err != nil { return 0, err }