From e104a26e694f47daa4328a3090f7dad09eeb83f2 Mon Sep 17 00:00:00 2001 From: Link Date: Mon, 3 Jun 2024 09:30:37 +0000 Subject: [PATCH] update cache --- route/static_route.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/route/static_route.go b/route/static_route.go index bb902d8..596a18a 100644 --- a/route/static_route.go +++ b/route/static_route.go @@ -2,6 +2,7 @@ package route import ( "os" + "path" "github.com/IceWhaleTech/CasaOS-Gateway/service" "github.com/gin-contrib/gzip" @@ -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() })