Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
chore: Add middleware to disable caching
Browse files Browse the repository at this point in the history
  • Loading branch information
devkcud committed Jul 15, 2024
1 parent 910665a commit 1ec73bd
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ func main() {
gin.SetMode(config.Router.GinMode)

router := gin.New()
router.Use(gin.Logger(), gin.Recovery(), middleware.DetectLanguage, middleware.GetAPIKey)
router.Use(gin.Logger(), gin.Recovery(), middleware.DisableCaching, middleware.DetectLanguage, middleware.GetAPIKey)

router.GET("/healthcare", func(ctx *gin.Context) {
ctx.Writer.WriteString(ctx.Keys["lang"].(translations.Translation).Hello)
15 changes: 15 additions & 0 deletions pkg/middleware/other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package middleware

import "github.com/gin-gonic/gin"

// Why? It solves a very specific problem where responses should not be cached,
// ensuring that each request receives fresh data based on its parameters.
// Caused due to cloud caching headers or smt like that idk
//
// HACK: Please, future me, fix this when you got time, it's kinda hacky
func DisableCaching(ctx *gin.Context) {
ctx.Header("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate")
ctx.Header("Pragma", "no-cache")
ctx.Header("Expires", "0")
ctx.Next()
}

0 comments on commit 1ec73bd

Please sign in to comment.