| 57 | } |
| 58 | |
| 59 | int RequestCache::Get(const Request& req, Response* res, uint64_t* key) { |
| 60 | if (!Enabled()) { |
| 61 | return -1; |
| 62 | } |
| 63 | uint64_t local_key = 0; |
| 64 | Hash(req, &local_key); |
| 65 | if (key != nullptr) { |
| 66 | *key = local_key; |
| 67 | } |
| 68 | std::lock_guard<std::recursive_mutex> lk(cache_mtx_); |
| 69 | auto iter = map_.find(local_key); |
| 70 | if (iter == map_.end()) { |
| 71 | LOG(INFO) << "key not found in cache"; |
| 72 | return -1; |
| 73 | } |
| 74 | auto entry = iter->second; |
| 75 | BuildResponse(entry, res); |
| 76 | UpdateLru(local_key); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int RequestCache::Put(const Request& req, const Response& res, uint64_t* key) { |
| 82 | if (!Enabled()) { |