Added gocache as a cache wrapper.
This commit is contained in:
parent
70d9d0f8fa
commit
3a45695083
9 changed files with 212 additions and 29 deletions
|
|
@ -2,16 +2,17 @@ package middleware
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func CacheControl(maxAge int) echo.MiddlewareFunc {
|
||||
func CacheControl(maxAge time.Duration) 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)
|
||||
v = fmt.Sprintf("public, max-age=%.0f", maxAge.Seconds())
|
||||
}
|
||||
c.Response().Header().Set("Cache-Control", v)
|
||||
return next(c)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue