| 307 | } |
| 308 | |
| 309 | bool PersistentCacheImpl::Insert(const Slice& key, CacheFile* file) { |
| 310 | std::lock_guard<std::mutex> _(lock_); |
| 311 | uint64_t cache_id; |
| 312 | if (metadata_.Lookup(key, &cache_id)) { |
| 313 | LEVELDB_LOG("File already exists, force evict it: %s\n", key.ToString().c_str()); |
| 314 | ForceEvict(key); |
| 315 | } |
| 316 | |
| 317 | // Insert file to meta data; |
| 318 | auto file_in_meta = metadata_.Lookup(file->cacheid()); |
| 319 | assert(file_in_meta.get() == file); |
| 320 | |
| 321 | auto f_info = metadata_.Insert(key, file); |
| 322 | metadata_size_.Set(metadata_.GetDBSize()); |
| 323 | |
| 324 | if (!f_info) { |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | file->SetInfo(f_info); |
| 329 | return true; |
| 330 | } |
| 331 | |
| 332 | std::vector<std::string> PersistentCacheImpl::GetAllKeys() { return metadata_.GetAllKeys(); } |
| 333 | |