mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-07-17 08:19:53 +00:00
20 lines
549 B
Go
20 lines
549 B
Go
package utils
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// SetCacheControlHeader sets the Cache-Control header for the response.
|
|
func SetCacheControlHeader(ctx *gin.Context, maxAge, staleWhileRevalidate time.Duration) {
|
|
_, ok := ctx.GetQuery("skipCache")
|
|
if !ok {
|
|
maxAgeSeconds := strconv.Itoa(int(maxAge.Seconds()))
|
|
staleWhileRevalidateSeconds := strconv.Itoa(int(staleWhileRevalidate.Seconds()))
|
|
ctx.Header("Cache-Control", "public, max-age="+maxAgeSeconds+", stale-while-revalidate="+staleWhileRevalidateSeconds)
|
|
}
|
|
|
|
}
|