给高频调用的路由加上 cache-control
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package middleware
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
const (
|
||||
CacheControlList = "public, max-age=300, s-maxage=1800, stale-while-revalidate=60"
|
||||
CacheControlCurve = "public, max-age=300, s-maxage=3600, stale-while-revalidate=120"
|
||||
CacheControlModelList = "public, max-age=30, s-maxage=300, stale-while-revalidate=30"
|
||||
)
|
||||
|
||||
func CacheControl(value string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Header("Cache-Control", value)
|
||||
c.Header("Vary", "Accept-Encoding")
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user