From 02d113b73888f1c3dc603ca6a91cb09ce1f71c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 31 Oct 2019 18:30:02 +0000 Subject: [PATCH] feat(api): cache /silence.json responses --- cmd/karma/views.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/karma/views.go b/cmd/karma/views.go index be61d306e..f000f282f 100644 --- a/cmd/karma/views.go +++ b/cmd/karma/views.go @@ -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)) }