aboutsummaryrefslogtreecommitdiff
path: root/zenserver/upstream/jupiter.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-21 20:41:34 +0200
committerStefan Boberg <[email protected]>2021-05-21 20:41:34 +0200
commit78dbac2648bbfe2a3687f37e06a3ed32241cb809 (patch)
tree5d053c139fb3738a6848c681015ea0d051a40423 /zenserver/upstream/jupiter.cpp
parentstd::min -> zen::Min (diff)
downloadzen-78dbac2648bbfe2a3687f37e06a3ed32241cb809.tar.xz
zen-78dbac2648bbfe2a3687f37e06a3ed32241cb809.zip
Partial refactoring of structured cache implementation - WIP
Diffstat (limited to 'zenserver/upstream/jupiter.cpp')
-rw-r--r--zenserver/upstream/jupiter.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/zenserver/upstream/jupiter.cpp b/zenserver/upstream/jupiter.cpp
index 363ebcd61..319a6f781 100644
--- a/zenserver/upstream/jupiter.cpp
+++ b/zenserver/upstream/jupiter.cpp
@@ -2,6 +2,8 @@
#include "jupiter.h"
+#include "cache/cachestore.h"
+
#include <fmt/format.h>
#include <zencore/compactbinary.h>
#include <zencore/iobuffer.h>
@@ -110,23 +112,38 @@ CloudCacheSession::Put(std::string_view BucketId, std::string_view Key, IoBuffer
}
void
-CloudCacheSession::Put(std::string_view BucketId, std::string_view Key, CbObjectView Data)
+CloudCacheSession::Put(std::string_view BucketId, const IoHash& Key, ZenCacheValue Data)
{
ExtendableStringBuilder<256> Uri;
Uri << m_CacheClient->ServiceUrl();
- Uri << "/api/v1/c/ddc/" << m_CacheClient->Namespace() << "/" << BucketId << "/" TESTING_PREFIX << Key;
+ Uri << "/api/v1/c/ddc/" << m_CacheClient->Namespace() << "/" << BucketId << "/" TESTING_PREFIX << Key.ToHexString();
auto& Session = m_SessionState->Session;
- IoHash Hash = Data.GetHash();
- MemoryView DataView = Data.GetView();
-
std::string Auth;
m_CacheClient->AcquireAccessToken(Auth);
Session.SetOption(cpr::Url{Uri.c_str()});
- Session.SetOption(
- cpr::Header{{"Authorization", Auth}, {"X-Jupiter-IoHash", Hash.ToHexString()}, {"Content-Type", "application/x-ue-cb"}});
- Session.SetOption(cpr::Body{(const char*)DataView.GetData(), DataView.GetSize()});
+
+ if (Data.IsCompactBinary)
+ {
+ CbObjectView Cbo(Data.Value.Data());
+ const IoHash Hash = Cbo.GetHash();
+ const MemoryView DataView = Cbo.GetView();
+
+ Session.SetOption(
+ cpr::Header{{"Authorization", Auth}, {"X-Jupiter-IoHash", Hash.ToHexString()}, {"Content-Type", "application/x-ue-cb"}});
+
+ Session.SetOption(cpr::Body{(const char*)DataView.GetData(), DataView.GetSize()});
+ }
+ else
+ {
+ const IoHash Hash = IoHash::HashMemory(Data.Value.Data(), Data.Value.Size());
+
+ Session.SetOption(
+ cpr::Header{{"Authorization", Auth}, {"X-Jupiter-IoHash", Hash.ToHexString()}, {"Content-Type", "application/x-ue-cb"}});
+
+ Session.SetOption(cpr::Body{(const char*)Data.Value.Data(), Data.Value.Size()});
+ }
cpr::Response Response = Session.Put();