diff --git a/src/ray/util/shared_lru.h b/src/ray/util/shared_lru.h index c02f2cf7bca3..8132e38b6f12 100644 --- a/src/ray/util/shared_lru.h +++ b/src/ray/util/shared_lru.h @@ -71,12 +71,13 @@ class SharedLruCache final { if (iter != cache_.end()) { lru_list_.splice(lru_list_.begin(), lru_list_, iter->second.lru_iterator); iter->second.value = std::move(value); - } else { - lru_list_.emplace_front(key); - Entry new_entry{std::move(value), lru_list_.begin()}; - cache_[std::move(key)] = std::move(new_entry); + return; } + lru_list_.emplace_front(key); + Entry new_entry{std::move(value), lru_list_.begin()}; + cache_[std::move(key)] = std::move(new_entry); + if (max_entries_ > 0 && lru_list_.size() > max_entries_) { const auto &stale_key = lru_list_.back(); cache_.erase(stale_key);