feat(api): cache /silence.json responses

This commit is contained in:
Łukasz Mierzwa
2019-10-31 18:30:02 +00:00
parent 77828d0bd5
commit 02d113b738

View File

@@ -412,6 +412,16 @@ func autocomplete(c *gin.Context) {
func silences(c *gin.Context) {
noCache(c)
start := time.Now()
cacheKey := c.Request.RequestURI
data, found := apiCache.Get(cacheKey)
if found {
c.Data(http.StatusOK, gin.MIMEJSON, data.([]byte))
logAlertsView(c, "HIT", time.Since(start))
return
}
dedupedSilences := []models.ManagedSilence{}
@@ -500,5 +510,8 @@ func silences(c *gin.Context) {
panic(err)
}
c.Data(http.StatusOK, gin.MIMEJSON, data)
apiCache.Set(cacheKey, data, time.Second*15)
c.Data(http.StatusOK, gin.MIMEJSON, data.([]byte))
logAlertsView(c, "MIS", time.Since(start))
}