Skip to content

Commit

Permalink
update static cache
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed May 22, 2024
1 parent c63f7c5 commit cf09381
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions route/static_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type StaticRoute struct {
state *service.State
}

var RouteCache = make(map[string]string)

func NewStaticRoute(state *service.State) *StaticRoute {
return &StaticRoute{
state: state,
Expand All @@ -31,9 +33,9 @@ func (s *StaticRoute) GetRoute() *gin.Engine {
r.Use(gzip.Gzip(gzip.DefaultCompression))

r.Use(func(ctx *gin.Context) {
if ctx.Request.URL.Path == "/" {
// disable caching for index.html (/) to fix blank page issue
if _, ok := RouteCache[ctx.Request.URL.Path]; !ok {
ctx.Writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate,proxy-revalidate, max-age=0")
RouteCache[ctx.Request.URL.Path] = ctx.Request.URL.Path
}
ctx.Next()
})
Expand Down

0 comments on commit cf09381

Please sign in to comment.