fix: Don't cache requests with params (#3113)

`ResponseExpirationCache` is using only `method` (or `command`) as a
key, but responses might be different with different params. This may
lead to a client getting incorrect response because of caching. This PR
fixes it by caching only requests without any additional params.
This commit is contained in:
Sergey Kuznetsov
2026-06-26 12:33:27 +01:00
committed by GitHub
parent 0b20dc728a
commit 87f0b480bf
7 changed files with 246 additions and 25 deletions

View File

@@ -277,7 +277,7 @@ LoadBalancer::forwardToRippled(
auto const cmd = boost::json::value_to<std::string>(request.at("command"));
if (shouldUseCache(isAdmin)) {
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
if (auto cachedResponse = forwardingCache_->get(cmd); cachedResponse) {
if (auto cachedResponse = forwardingCache_->get(cmd, request); cachedResponse) {
forwardingCounters_.cacheHit.get() += 1;
return *std::move(cachedResponse);
}
@@ -311,8 +311,10 @@ LoadBalancer::forwardToRippled(
}
if (response) {
if (shouldUseCache(isAdmin) and not response->contains("error"))
forwardingCache_->put(cmd, *response); // NOLINT(bugprone-unchecked-optional-access)
if (shouldUseCache(isAdmin) and not response->contains("error")) {
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
forwardingCache_->put(cmd, request, *response);
}
return *std::move(response);
}