This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add middleware to disable caching
- Loading branch information
Showing
2 changed files
with
16 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |