MCPcopy Index your code
hub / github.com/golang/groupcache / populateCache

Method populateCache

groupcache.go:346–369  ·  view source on GitHub ↗
(key string, value ByteView, cache *cache)

Source from the content-addressed store, hash-verified

344}
345
346func (g *Group) populateCache(key string, value ByteView, cache *cache) {
347 if g.cacheBytes <= 0 {
348 return
349 }
350 cache.add(key, value)
351
352 // Evict items from cache(s) if necessary.
353 for {
354 mainBytes := g.mainCache.bytes()
355 hotBytes := g.hotCache.bytes()
356 if mainBytes+hotBytes <= g.cacheBytes {
357 return
358 }
359
360 // TODO(bradfitz): this is good-enough-for-now logic.
361 // It should be something based on measurements and/or
362 // respecting the costs of different resources.
363 victim := &g.mainCache
364 if hotBytes > mainBytes/8 {
365 victim = &g.hotCache
366 }
367 victim.removeOldest()
368 }
369}
370
371// CacheType represents a type of cache.
372type CacheType int

Callers 2

loadMethod · 0.95
getFromPeerMethod · 0.95

Calls 3

addMethod · 0.80
bytesMethod · 0.80
removeOldestMethod · 0.80

Tested by

no test coverage detected