| 235 | } |
| 236 | |
| 237 | void add_to_cache(const K* batch_ids, const size_t batch_size) { |
| 238 | mutex_lock l(mu_); |
| 239 | std::vector<K> ids_to_cache(batch_size); |
| 240 | int64 nums_to_cache = 0; |
| 241 | for (size_t i = 0; i < batch_size; ++i) { |
| 242 | K id = batch_ids[i]; |
| 243 | auto it_prefetch = prefetch_id_table.find(id); |
| 244 | if (it_prefetch == prefetch_id_table.end()) { |
| 245 | LOG(FATAL)<<"The id should be prefetched before being used."; |
| 246 | } |
| 247 | it_prefetch->second->UnRef(); |
| 248 | if (it_prefetch->second->ref_count() == 0) { |
| 249 | delete it_prefetch->second; |
| 250 | prefetch_id_table.erase(id); |
| 251 | ids_to_cache[nums_to_cache] = id; |
| 252 | nums_to_cache++; |
| 253 | } |
| 254 | } |
| 255 | update(ids_to_cache.data(), nums_to_cache, false); |
| 256 | } |
| 257 | |
| 258 | private: |
| 259 | class LRUNode { |