Skip to content

Commit

Permalink
add Cache for stat api
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed May 30, 2024
1 parent cb1ff77 commit 5f5623c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,16 @@ func (cr *Cluster) apiV0Stat(rw http.ResponseWriter, req *http.Request) {
limited.SetSkipRateLimit(req)
name := req.URL.Path
if name == "" {
rw.Header().Set("Cache-Control", "public, max-age=60")
writeJson(rw, http.StatusOK, &cr.stats)
return
}
data, err := cr.stats.MarshalSubStat(name)
if err != nil {
http.Error(rw, "Error when encoding response: "+err.Error(), http.StatusInternalServerError)
return
}
rw.Header().Set("Cache-Control", "public, max-age=30")
writeJson(rw, http.StatusOK, (json.RawMessage)(data))
}

Expand Down

0 comments on commit 5f5623c

Please sign in to comment.