From 5a0a9aa65e4b7822ae7f986326e9f15689abaf15 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 29 Aug 2018 17:21:30 +0200 Subject: [PATCH] reset cache if empty --- common/strmatcher/strmatcher.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/strmatcher/strmatcher.go b/common/strmatcher/strmatcher.go index 5314d08a..7f4eac52 100644 --- a/common/strmatcher/strmatcher.go +++ b/common/strmatcher/strmatcher.go @@ -140,6 +140,10 @@ func NewCachedMatcherGroup(g *MatcherGroup) *CachedMatcherGroup { r.Lock() defer r.Unlock() + if len(r.cache) == 0 { + return nil + } + expire := time.Now().Add(-1 * time.Second * 120) for p, e := range r.cache { if e.timestamp.Before(expire) { @@ -147,6 +151,10 @@ func NewCachedMatcherGroup(g *MatcherGroup) *CachedMatcherGroup { } } + if len(r.cache) == 0 { + r.cache = make(map[string]cacheEntry) + } + return nil }, }