Explorar o código

reset cache if empty

Darien Raymond %!s(int64=7) %!d(string=hai) anos
pai
achega
5a0a9aa65e
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      common/strmatcher/strmatcher.go

+ 8 - 0
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
 		},
 	}