modulepackage
1.1.1
Repository: https://github.com/joeig/gin-cachecontrol.git
Documentation: pkg.go.dev
# README
Cache-Control middleware for Gin
This Gin middleware generates cache control-headers.
Usage
package main
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/joeig/gin-cachecontrol"
)
func main() {
router := gin.Default()
router.Use(cachecontrol.New(&cachecontrol.Config{
MustRevalidate: true,
NoCache: false,
NoStore: false,
NoTransform: false,
Public: true,
Private: false,
ProxyRevalidate: true,
MaxAge: cachecontrol.Duration(30 * time.Minute),
SMaxAge: nil,
Immutable: false,
StaleWhileRevalidate: cachecontrol.Duration(2 * time.Hour),
StaleIfError: cachecontrol.Duration(2 * time.Hour),
}))
// Alternatively, you can choose a preset:
// router.Use(cachecontrol.New(cachecontrol.NoCachePreset))
router.GET("/", func(ginCtx *gin.Context) {
ginCtx.String(http.StatusOK, "Hello, Gopher!")
})
router.Run()
}
Documentation
See GoDoc.
# Variables
CacheAssetsForeverPreset is a cache-control configuration preset which advices the HTTP client and all caches in between to cache the object forever without revalidation.
NoCachePreset is a cache-control configuration preset which advices the HTTP client not to cache at all.