| 126 | } |
| 127 | |
| 128 | int RequestCache::BuildCacheEntry(const Response& res, CacheEntry* entry) { |
| 129 | if (entry == nullptr) { |
| 130 | return -1; |
| 131 | } |
| 132 | std::lock_guard<std::recursive_mutex> lk(cache_mtx_); |
| 133 | int size = res.ByteSize(); |
| 134 | if (size >= cache_size_) { |
| 135 | LOG(INFO) << "res size[" << size << "] larger than cache_size[" |
| 136 | << cache_size_ << "]"; |
| 137 | return -1; |
| 138 | } |
| 139 | while (size > GetFreeCacheSize()) { |
| 140 | if (RemoveOne() != 0) { |
| 141 | LOG(ERROR) << "RemoveOne failed so can not build entry"; |
| 142 | return -1; |
| 143 | } |
| 144 | } |
| 145 | entry->buf_ = res.SerializeAsString(); |
| 146 | used_size_ += size; |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | void RequestCache::UpdateLru(uint64_t key) { |
| 151 | std::lock_guard<std::recursive_mutex> lk(cache_mtx_); |
nothing calls this directly
no outgoing calls
no test coverage detected