Mercurial > gemma
changeset 4889:ab6eb160cd29
Sounding result cache: Start background cache cleanup lazily only when the cache is really used.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 09 Feb 2020 20:24:54 +0100 |
parents | af38a19f615a |
children | 5d9c7fcda566 |
files | pkg/mesh/cache.go |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/mesh/cache.go Tue Feb 04 16:29:49 2020 +0100 +++ b/pkg/mesh/cache.go Sun Feb 09 20:24:54 2020 +0100 @@ -68,13 +68,7 @@ ` ) -var cache = Cache{ - entries: map[cacheKey]*cacheEntry{}, -} - -func init() { - go cache.background() -} +var cache Cache func (c *Cache) background() { for { @@ -129,6 +123,12 @@ c.Lock() defer c.Unlock() + // Start background cleanup lazily. + if c.entries == nil { + c.entries = map[cacheKey]*cacheEntry{} + go c.background() + } + key := cacheKey{date, bottleneck} entry := c.entries[key]