MCPcopy Create free account
hub / github.com/cortexproject/cortex / NewFifoCache

Function NewFifoCache

pkg/chunk/cache/fifo_cache.go:94–178  ·  view source on GitHub ↗

NewFifoCache returns a new initialised FifoCache of size.

(name string, cfg FifoCacheConfig, reg prometheus.Registerer, logger log.Logger)

Source from the content-addressed store, hash-verified

92
93// NewFifoCache returns a new initialised FifoCache of size.
94func NewFifoCache(name string, cfg FifoCacheConfig, reg prometheus.Registerer, logger log.Logger) *FifoCache {
95 if cfg.DeprecatedSize > 0 {
96 flagext.DeprecatedFlagsUsed.Inc()
97 level.Warn(logger).Log("msg", "running with DEPRECATED flag fifocache.size, use fifocache.max-size-items or fifocache.max-size-bytes instead", "cache", name)
98 cfg.MaxSizeItems = cfg.DeprecatedSize
99 }
100 maxSizeBytes, _ := parsebytes(cfg.MaxSizeBytes)
101
102 if maxSizeBytes == 0 && cfg.MaxSizeItems == 0 {
103 // zero cache capacity - no need to create cache
104 level.Warn(logger).Log("msg", "neither fifocache.max-size-bytes nor fifocache.max-size-items is set", "cache", name)
105 return nil
106 }
107 return &FifoCache{
108 maxSizeItems: cfg.MaxSizeItems,
109 maxSizeBytes: maxSizeBytes,
110 validity: cfg.Validity,
111 entries: make(map[string]*list.Element),
112 lru: list.New(),
113
114 entriesAdded: promauto.With(reg).NewCounter(prometheus.CounterOpts{
115 Namespace: "querier",
116 Subsystem: "cache",
117 Name: "added_total",
118 Help: "The total number of Put calls on the cache",
119 ConstLabels: prometheus.Labels{"cache": name},
120 }),
121
122 entriesAddedNew: promauto.With(reg).NewCounter(prometheus.CounterOpts{
123 Namespace: "querier",
124 Subsystem: "cache",
125 Name: "added_new_total",
126 Help: "The total number of new entries added to the cache",
127 ConstLabels: prometheus.Labels{"cache": name},
128 }),
129
130 entriesEvicted: promauto.With(reg).NewCounter(prometheus.CounterOpts{
131 Namespace: "querier",
132 Subsystem: "cache",
133 Name: "evicted_total",
134 Help: "The total number of evicted entries",
135 ConstLabels: prometheus.Labels{"cache": name},
136 }),
137
138 entriesCurrent: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
139 Namespace: "querier",
140 Subsystem: "cache",
141 Name: "entries",
142 Help: "The total number of entries",
143 ConstLabels: prometheus.Labels{"cache": name},
144 }),
145
146 totalGets: promauto.With(reg).NewCounter(prometheus.CounterOpts{
147 Namespace: "querier",
148 Subsystem: "cache",
149 Name: "gets_total",
150 Help: "The total number of Get calls",
151 ConstLabels: prometheus.Labels{"cache": name},

Callers 3

NewFunction · 0.85
TestFifoCacheEvictionFunction · 0.85
TestFifoCacheExpiryFunction · 0.85

Calls 3

parsebytesFunction · 0.85
IncMethod · 0.45
LogMethod · 0.45

Tested by 2

TestFifoCacheEvictionFunction · 0.68
TestFifoCacheExpiryFunction · 0.68