summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-05-16 02:43:13 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-05-16 02:43:13 +0300
commitcd123987076fddcb6cbd4a90fbcff5675f82b563 (patch)
treedf64f8ab79c4c5b62760c1187f443f5acffcefa5 /src/server
parenta332a974c00130fda40a94ee61a0c51e246cd0ab (diff)
server/cache: fix cache collision for commands with different arguments
Diffstat (limited to 'src/server')
-rw-r--r--src/server/server.cc9
-rw-r--r--src/server/server.h1
2 files changed, 7 insertions, 3 deletions
diff --git a/src/server/server.cc b/src/server/server.cc
index ab1db9e..2c2ff33 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -114,7 +114,7 @@ std::shared_ptr<p18::response_type::BaseResponse> Server::executeCommand(p18::Co
auto it = cache_.find(commandType);
if (it != cache_.end()) {
auto cr = it->second;
- if (voltronic::timestamp() - cr.time <= cacheTimeout_) {
+ if (voltronic::timestamp() - cr.time <= cacheTimeout_ && arguments == cr.arguments) {
return cr.response;
}
@@ -123,7 +123,11 @@ std::shared_ptr<p18::response_type::BaseResponse> Server::executeCommand(p18::Co
try {
auto response = client_.execute(commandType, arguments);
- CachedResponse cr{voltronic::timestamp(), response};
+ CachedResponse cr {
+ .time = voltronic::timestamp(),
+ .arguments = arguments,
+ .response = response
+ };
cache_[commandType] = cr;
return response;
}
@@ -141,5 +145,4 @@ std::shared_ptr<p18::response_type::BaseResponse> Server::executeCommand(p18::Co
}
}
-
} \ No newline at end of file
diff --git a/src/server/server.h b/src/server/server.h
index 76b2a1b..e083c7e 100644
--- a/src/server/server.h
+++ b/src/server/server.h
@@ -28,6 +28,7 @@ class Connection;
struct CachedResponse {
u64 time;
+ std::vector<std::string> arguments;
std::shared_ptr<p18::response_type::BaseResponse> response;
};