Added cache control middleware.

This commit is contained in:
mikestefanello 2021-12-03 08:18:40 -05:00
parent 70d777d09e
commit 3c2c698269
2 changed files with 31 additions and 14 deletions

20
middleware/cache.go Normal file
View file

@ -0,0 +1,20 @@
package middleware
import (
"fmt"
"github.com/labstack/echo/v4"
)
func CacheControl(maxAge int) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
v := "no-cache, no-store"
if maxAge > 0 {
v = fmt.Sprintf("public, max-age=%d", maxAge)
}
c.Response().Header().Set("Cache-Control", v)
return next(c)
}
}
}