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

Method Get

pkg/chunk/cache/fifo_cache.go:275–295  ·  view source on GitHub ↗

Get returns the stored value against the key and when the key was last updated.

(ctx context.Context, key string)

Source from the content-addressed store, hash-verified

273
274// Get returns the stored value against the key and when the key was last updated.
275func (c *FifoCache) Get(ctx context.Context, key string) ([]byte, bool) {
276 c.totalGets.Inc()
277
278 c.lock.RLock()
279 defer c.lock.RUnlock()
280
281 element, ok := c.entries[key]
282 if ok {
283 entry := element.Value.(*cacheEntry)
284 if c.validity == 0 || time.Since(entry.updated) < c.validity {
285 return entry.value, true
286 }
287
288 c.totalMisses.Inc()
289 c.staleGets.Inc()
290 return nil, false
291 }
292
293 c.totalMisses.Inc()
294 return nil, false
295}
296
297func sizeOf(item *cacheEntry) uint64 {
298 return uint64(int(unsafe.Sizeof(*item)) + // size of cacheEntry

Callers 3

FetchMethod · 0.95
TestFifoCacheEvictionFunction · 0.95
TestFifoCacheExpiryFunction · 0.95

Calls 1

IncMethod · 0.45

Tested by 2

TestFifoCacheEvictionFunction · 0.76
TestFifoCacheExpiryFunction · 0.76