| 546 | class ShardedCache : public Cache { |
| 547 | public: |
| 548 | explicit ShardedCache(size_t capacity, const string& id) |
| 549 | : shard_bits_(DetermineShardBits()) { |
| 550 | // A cache is often a singleton, so: |
| 551 | // 1. We reuse its MemTracker if one already exists, and |
| 552 | // 2. It is directly parented to the root MemTracker. |
| 553 | mem_tracker_ = MemTracker::FindOrCreateGlobalTracker( |
| 554 | -1, strings::Substitute("$0-sharded_$1_cache", id, ToString(policy))); |
| 555 | |
| 556 | int num_shards = 1 << shard_bits_; |
| 557 | const size_t per_shard = (capacity + (num_shards - 1)) / num_shards; |
| 558 | for (int s = 0; s < num_shards; s++) { |
| 559 | unique_ptr<CacheShard<policy>> shard( |
| 560 | new CacheShard<policy>(mem_tracker_.get())); |
| 561 | shard->SetCapacity(per_shard); |
| 562 | shards_.push_back(shard.release()); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | virtual ~ShardedCache() { |
| 567 | STLDeleteElements(&shards_); |
nothing calls this directly
no test coverage detected