From af7170675dae5380a5e99d49fec31f557e66177f Mon Sep 17 00:00:00 2001 From: Krishna Srinivas Date: Fri, 26 Feb 2016 18:49:35 +0530 Subject: [PATCH] caching: disable caching of index.html and enable caching for other UI asset files. --- generic-handlers.go | 17 +++++++++++++++-- web-handlers.go | 9 --------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/generic-handlers.go b/generic-handlers.go index a36c60b2a..2d7bd63ff 100644 --- a/generic-handlers.go +++ b/generic-handlers.go @@ -20,6 +20,7 @@ import ( "errors" "net/http" "path" + "regexp" "strings" "time" @@ -125,8 +126,20 @@ func setBrowserCacheControlHandler(h http.Handler) http.Handler { func (h cacheControlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" && strings.Contains(r.Header.Get("User-Agent"), "Mozilla") { - // Expire cache in one hour for all browser requests. - w.Header().Set("Cache-Control", "public, max-age=3600") + // For all browser requests set appropriate Cache-Control policies + match, e := regexp.MatchString(privateBucket+`/([^/]+\.js|favicon.ico)`, r.URL.Path) + if e != nil { + writeErrorResponse(w, r, InternalError, r.URL.Path) + return + } + if match { + // For assets set cache expiry of one year. For each release, the name + // of the asset name will change and hence it can not be served from cache. + w.Header().Set("Cache-Control", "max-age=31536000") + } else if strings.HasPrefix(r.URL.Path, privateBucket+"/") { + // For non asset requests we serve index.html which will never be cached. + w.Header().Set("Cache-Control", "no-store") + } } h.handler.ServeHTTP(w, r) } diff --git a/web-handlers.go b/web-handlers.go index 6af7e13cc..2cd7f5744 100644 --- a/web-handlers.go +++ b/web-handlers.go @@ -58,15 +58,6 @@ type GenericRep struct { UIVersion string `json:"uiVersion"` } -// GenericArgs - empty struct -type GenericArgs struct{} - -// GetUIVersion - get UI version -func (web webAPI) GetUIVersion(r *http.Request, args *GenericArgs, reply *GenericRep) error { - reply.UIVersion = miniobrowser.UIVersion - return nil -} - // ServerInfoRep - server info reply. type ServerInfoRep struct { MinioVersion string