From cd123987076fddcb6cbd4a90fbcff5675f82b563 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 16 May 2021 02:43:13 +0300 Subject: server/cache: fix cache collision for commands with different arguments --- src/server/server.cc | 9 ++++++--- src/server/server.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/server') 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 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 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 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 arguments; std::shared_ptr response; }; -- cgit v1.2.3