Skip to content

Commit

Permalink
update cache
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Jun 3, 2024
1 parent cf09381 commit e104a26
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions route/static_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package route

import (
"os"
"path"

"github.com/IceWhaleTech/CasaOS-Gateway/service"
"github.com/gin-contrib/gzip"
Expand Down Expand Up @@ -33,9 +34,14 @@ func (s *StaticRoute) GetRoute() *gin.Engine {
r.Use(gzip.Gzip(gzip.DefaultCompression))

r.Use(func(ctx *gin.Context) {
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
// Extract the file name from the path
_, file := path.Split(ctx.Request.URL.Path)
// If the file name contains a dot, it's likely a file
if path.Ext(file) == "" {
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 e104a26

Please sign in to comment.