feat(cache): set max-age for public accessible static resources

This commit is contained in:
HFO4
2022-12-14 15:28:19 +08:00
parent 8c5ba89f7d
commit 50a3917a65
5 changed files with 38 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package middleware
import (
"fmt"
model "github.com/cloudreve/Cloudreve/v3/models"
"github.com/cloudreve/Cloudreve/v3/pkg/hashid"
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
@@ -51,3 +52,11 @@ func Sandbox() gin.HandlerFunc {
c.Header("Content-Security-Policy", "sandbox")
}
}
// StaticResourceCache 使用静态资源缓存策略
func StaticResourceCache() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Cache-Control", fmt.Sprintf("public, max-age=%d", model.GetIntSetting("public_resource_maxage", 86400)))
}
}