From 78dbac2648bbfe2a3687f37e06a3ed32241cb809 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 21 May 2021 20:41:34 +0200 Subject: Partial refactoring of structured cache implementation - WIP --- zenserver/upstream/jupiter.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'zenserver/upstream/jupiter.cpp') 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 #include #include @@ -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(); -- cgit v1.2.3