github.com/netdata/go.d.plugin@v0.58.1/modules/prometheus/cache.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package prometheus
     4  
     5  import (
     6  	"github.com/netdata/go.d.plugin/agent/module"
     7  )
     8  
     9  func newCache() *cache {
    10  	return &cache{entries: make(map[string]*cacheEntry)}
    11  }
    12  
    13  type (
    14  	cache struct {
    15  		entries map[string]*cacheEntry
    16  	}
    17  
    18  	cacheEntry struct {
    19  		seen         bool
    20  		notSeenTimes int
    21  		charts       []*module.Chart
    22  	}
    23  )
    24  
    25  func (c *cache) hasP(key string) bool {
    26  	v, ok := c.entries[key]
    27  	if !ok {
    28  		v = &cacheEntry{}
    29  		c.entries[key] = v
    30  	}
    31  	v.seen = true
    32  	v.notSeenTimes = 0
    33  
    34  	return ok
    35  }
    36  
    37  func (c *cache) addChart(key string, chart *module.Chart) {
    38  	if v, ok := c.entries[key]; ok {
    39  		v.charts = append(v.charts, chart)
    40  	}
    41  }