| 464 | } |
| 465 | |
| 466 | void add_to_cache(const K* batch_ids, const size_t batch_size) { |
| 467 | mutex_lock l(mu_); |
| 468 | std::vector<K> ids_to_cache(batch_size); |
| 469 | std::vector<int64> freqs_to_cache(batch_size); |
| 470 | int64 nums_to_cache = 0; |
| 471 | for (size_t i = 0; i < batch_size; ++i) { |
| 472 | K id = batch_ids[i]; |
| 473 | auto it_prefetch = prefetch_id_table.find(id); |
| 474 | if (it_prefetch == prefetch_id_table.end()) { |
| 475 | LOG(FATAL)<<"The id should be prefetched before being used."; |
| 476 | } |
| 477 | it_prefetch->second->UnRef(); |
| 478 | if (it_prefetch->second->ref_count() == 0) { |
| 479 | int64 freq = it_prefetch->second->freq(); |
| 480 | delete it_prefetch->second; |
| 481 | prefetch_id_table.erase(id); |
| 482 | ids_to_cache[nums_to_cache] = id; |
| 483 | freqs_to_cache[nums_to_cache] = freq; |
| 484 | nums_to_cache++; |
| 485 | } |
| 486 | } |
| 487 | const int64* versions_to_cache = nullptr; |
| 488 | update(ids_to_cache.data(), nums_to_cache, |
| 489 | versions_to_cache, freqs_to_cache.data(), |
| 490 | false); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | private: |