fix: Don't cache responses to admin's requests (#3058)

This commit is contained in:
Sergey Kuznetsov
2026-05-05 17:00:59 +01:00
committed by GitHub
parent a7090f5b19
commit e974e1899f
3 changed files with 96 additions and 3 deletions

View File

@@ -275,7 +275,8 @@ LoadBalancer::forwardToRippled(
return std::unexpected{rpc::ClioError::RpcCommandIsMissing};
auto const cmd = boost::json::value_to<std::string>(request.at("command"));
if (forwardingCache_) {
if (shouldUseCache(isAdmin)) {
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
if (auto cachedResponse = forwardingCache_->get(cmd); cachedResponse) {
forwardingCounters_.cacheHit.get() += 1;
return *std::move(cachedResponse);
@@ -310,8 +311,8 @@ LoadBalancer::forwardToRippled(
}
if (response) {
if (forwardingCache_ and not response->contains("error"))
forwardingCache_->put(cmd, *response);
if (shouldUseCache(isAdmin) and not response->contains("error"))
forwardingCache_->put(cmd, *response); // NOLINT(bugprone-unchecked-optional-access)
return *std::move(response);
}
@@ -415,4 +416,10 @@ LoadBalancer::chooseForwardingSource()
}
}
bool
LoadBalancer::shouldUseCache(bool isAdmin) const
{
return forwardingCache_.has_value() and not isAdmin;
}
} // namespace etl