aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcache.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-20 14:05:01 +0200
committerStefan Boberg <[email protected]>2021-05-20 14:05:01 +0200
commit049f51d56a59299bcbf718bf1a55d7e745f2cf57 (patch)
tree575745847cd542dde5e826da77796da2ebd8e85c /zenserver/cache/structuredcache.cpp
parentAdded tentative Jupiter structured data endpoints (diff)
downloadzen-049f51d56a59299bcbf718bf1a55d7e745f2cf57.tar.xz
zen-049f51d56a59299bcbf718bf1a55d7e745f2cf57.zip
WIP structured cache endpoints - tactical check-in not fully functional yet
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
-rw-r--r--zenserver/cache/structuredcache.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index 0d62f297c..e90f838da 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -4,6 +4,7 @@
#include <zencore/fmtutils.h>
#include <zencore/httpserver.h>
+#include <zencore/timer.h>
#include "cachestore.h"
#include "structuredcache.h"
@@ -14,11 +15,19 @@
namespace zen {
+using namespace std::literals;
+
HttpStructuredCacheService::HttpStructuredCacheService(std::filesystem::path RootPath, zen::CasStore& InStore)
: m_CasStore(InStore)
, m_CacheStore(InStore, RootPath)
{
spdlog::info("initializing structured cache at '{}'", RootPath);
+
+ m_Cloud = new CloudCacheClient("https://jupiter.devtools.epicgames.com"sv,
+ "ue4.ddc"sv /* namespace */,
+ "https://epicgames.okta.com/oauth2/auso645ojjWVdRI3d0x7/v1/token"sv /* provider */,
+ "0oao91lrhqPiAlaGD0x7"sv /* client id */,
+ "-GBWjjenhCgOwhxL5yBKNJECVIoDPH0MK4RDuN7d"sv /* oauth secret */);
}
HttpStructuredCacheService::~HttpStructuredCacheService()
@@ -78,9 +87,45 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request)
CacheValue Value;
Value.Value = Body;
+ HttpContentType ContentType = Request.RequestContentType();
+
+ switch (ContentType)
+ {
+ case HttpContentType::kUnknownContentType:
+ case HttpContentType::kBinary:
+ Value.IsCompactBinary = false;
+ break;
+
+ case HttpContentType::kCbObject:
+ Value.IsCompactBinary = true;
+ break;
+
+ default:
+ return Request.WriteResponse(zen::HttpResponse::BadRequest);
+ }
+
m_CacheStore.Put(Ref.BucketSegment, Ref.HashKey, Value);
- Request.WriteResponse(zen::HttpResponse::Created);
+ // This is currently synchronous for simplicity and debuggability but should be
+ // made asynchronous
+
+ if (m_Cloud)
+ {
+ CloudCacheSession Session(m_Cloud);
+
+ zen::Stopwatch Timer;
+
+ if (Session.Put(Ref.BucketSegment, Ref.HashKey))
+ {
+ spdlog::debug("upstream PUT succeeded after {:5}! {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()), Ref.HashKey);
+ }
+ else
+ {
+ spdlog::debug("upstream PUT failed after {:5}! {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()), Ref.HashKey);
+ }
+ }
+
+ return Request.WriteResponse(zen::HttpResponse::Created);
}
else
{