diff options
author | Henry Castro <hcastro@collabora.com> | 2022-06-22 10:09:12 -0400 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2022-06-27 16:04:32 +0100 |
commit | e814bb90cf45e71d2081b575a212959fbe7a9418 (patch) | |
tree | 58d87e870d4805e42b9ced0bf8984f89ac2c4782 | |
parent | wsd: proxy: add cache response (diff) | |
download | online-e814bb90cf45e71d2081b575a212959fbe7a9418.tar.gz online-e814bb90cf45e71d2081b575a212959fbe7a9418.zip |
wsd: proxy: handle cache max age
Change-Id: Id7716388ec776e1823f3d395100e75b31324b434
Signed-off-by: Henry Castro <hcastro@collabora.com>
-rw-r--r-- | wsd/ProxyRequestHandler.cpp | 14 | ||||
-rw-r--r-- | wsd/ProxyRequestHandler.hpp | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/wsd/ProxyRequestHandler.cpp b/wsd/ProxyRequestHandler.cpp index 6b868140d2..c05a2587be 100644 --- a/wsd/ProxyRequestHandler.cpp +++ b/wsd/ProxyRequestHandler.cpp @@ -15,11 +15,19 @@ #include <net/HttpHelper.hpp> std::map<std::string, std::shared_ptr<http::Response>> ProxyRequestHandler::CacheFileHash; +std::chrono::system_clock::time_point ProxyRequestHandler::MaxAge; void ProxyRequestHandler::handleRequest(const std::string& relPath, const std::shared_ptr<StreamSocket>& socket) { Poco::URI uriProxy(ProxyServer); + const auto timeNow = std::chrono::system_clock::now(); + + if (MaxAge > std::chrono::system_clock::time_point() && timeNow > MaxAge) + { + CacheFileHash.clear(); + MaxAge = std::chrono::system_clock::time_point(); + } const auto cacheEntry = CacheFileHash.find(relPath); if (cacheEntry != CacheFileHash.end()) @@ -39,9 +47,15 @@ void ProxyRequestHandler::handleRequest(const std::string& relPath, { try { + const auto callbackNow = std::chrono::system_clock::now(); std::shared_ptr<http::Response> httpResponse = httpSession->response(); if (httpResponse->statusLine().statusCode() == 200) { + if (MaxAge == std::chrono::system_clock::time_point()) + { + MaxAge = callbackNow + std::chrono::hours(10); + } + CacheFileHash[httpSession->getUrl()] = httpResponse; socket->sendAndShutdown(*httpResponse); } diff --git a/wsd/ProxyRequestHandler.hpp b/wsd/ProxyRequestHandler.hpp index a978a90916..ab621131d3 100644 --- a/wsd/ProxyRequestHandler.hpp +++ b/wsd/ProxyRequestHandler.hpp @@ -17,6 +17,7 @@ public: const std::shared_ptr<StreamSocket>& socket); private: + static std::chrono::system_clock::time_point MaxAge; static constexpr auto ProxyServer = "https://www.collaboraoffice.com"; static std::map<std::string, std::shared_ptr<http::Response>> CacheFileHash; }; |