Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cache-Control middleware for Gin

License

NotificationsYou must be signed in to change notification settings

joeig/gin-cachecontrol

Repository files navigation

This Gin middleware generates cache-control headers.

Test coverageGo Report CardPkgGoDev

Setup

go get -u go.eigsys.de/gin-cachecontrol/v2
import"go.eigsys.de/gin-cachecontrol/v2"

Usage

With a preset

// Apply globally:r.Use(cachecontrol.New(cachecontrol.NoCachePreset))// Apply to specific routes:cacheForever:=cachecontrol.New(cachecontrol.CacheAssetsForeverPreset)r.GET("/favicon.ico",cacheForever,faviconHandler)

Supported presets (documentation):

  • cachecontrol.NoCachePreset
  • cachecontrol.CacheAssetsForeverPreset (you may only want this for carefully selected routes)

With a custom configuration

r.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),        }    ))

Documentation

SeeGo reference.


[8]ページ先頭

©2009-2025 Movatter.jp