(key string, value ByteView, cache *cache)
| 344 | } |
| 345 | |
| 346 | func (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. |
| 372 | type CacheType int |
no test coverage detected