aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcache.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-11-10 08:47:57 +0100
committerPer Larsson <[email protected]>2021-11-10 08:47:57 +0100
commit424be141e88b04b4de7ab5def2c29b03f5f72d48 (patch)
tree2feba55ce29e78f9449f46c7c511cc5446bc9624 /zenserver/cache/structuredcache.cpp
parentSort cache keys when resolving payload ID's. (diff)
downloadzen-424be141e88b04b4de7ab5def2c29b03f5f72d48.tar.xz
zen-424be141e88b04b4de7ab5def2c29b03f5f72d48.zip
Handle cache record policy.
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
-rw-r--r--zenserver/cache/structuredcache.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index decad2f04..073192c12 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -114,9 +114,7 @@ HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request)
if (Key == "$batch")
{
- const auto QueryParams = Request.GetQueryParams();
- CachePolicy Policy = ParseCachePolicy(QueryParams);
- return HandleBatchRequest(Request, Policy);
+ return HandleBatchRequest(Request);
}
if (std::all_of(begin(Key), end(Key), [](const char c) { return std::isalnum(c); }))
@@ -782,10 +780,8 @@ HttpStructuredCacheService::ValidateKeyUri(HttpServerRequest& Request, CacheRef&
}
void
-HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request, CachePolicy Policy)
+HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request)
{
- using namespace fmt::literals;
-
switch (auto Verb = Request.RequestVerb())
{
using enum HttpVerb;
@@ -805,11 +801,11 @@ HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request,
if (Method == "get-cache-records"sv)
{
- HandleBatchGetCacheRecords(Request, BatchRequest, Policy);
+ HandleBatchGetCacheRecords(Request, BatchRequest);
}
else if (Method == "get-cache-chunks"sv)
{
- HandleBatchGetCachePayloads(Request, BatchRequest, Policy);
+ HandleBatchGetCachePayloads(Request, BatchRequest);
}
else
{
@@ -824,19 +820,21 @@ HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request,
}
void
-HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView BatchRequest, CachePolicy Policy)
+HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView BatchRequest)
{
using namespace fmt::literals;
- const bool SkipData = (Policy & CachePolicy::SkipData) == CachePolicy::SkipData;
- const bool SkipAttachments = (Policy & CachePolicy::SkipAttachments) == CachePolicy::SkipAttachments;
- const bool QueryUpstream = m_UpstreamCache && ((Policy & CachePolicy::QueryRemote) == CachePolicy::QueryRemote);
-
const std::string_view Method = BatchRequest["method"sv].AsString();
ZEN_ASSERT(Method == "get-cache-records"sv);
CbObjectView Params = BatchRequest["params"sv].AsObjectView();
+ CacheRecordPolicy Policy;
+ CacheRecordPolicy::FromCompactBinary(Params["policy"sv].AsObjectView(), Policy);
+
+ const bool SkipAttachments = (Policy.GetRecordPolicy() & CachePolicy::SkipAttachments) == CachePolicy::SkipAttachments;
+ const bool QueryUpstream = m_UpstreamCache && ((Policy.GetRecordPolicy() & CachePolicy::QueryRemote) == CachePolicy::QueryRemote);
+
std::vector<CacheKey> CacheKeys;
std::vector<IoBuffer> CacheValues;
std::vector<IoBuffer> Payloads;
@@ -855,6 +853,11 @@ HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& R
CacheValues.resize(CacheKeys.size());
+ if (!SkipAttachments)
+ {
+ Payloads.reserve(CacheKeys.size());
+ }
+
for (size_t Idx = 0; const CacheKey& Key : CacheKeys)
{
ZenCacheValue CacheValue;
@@ -971,7 +974,7 @@ HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& R
}
void
-HttpStructuredCacheService::HandleBatchGetCachePayloads(zen::HttpServerRequest& Request, CbObjectView BatchRequest, CachePolicy Policy)
+HttpStructuredCacheService::HandleBatchGetCachePayloads(zen::HttpServerRequest& Request, CbObjectView BatchRequest)
{
using namespace fmt::literals;
@@ -999,15 +1002,16 @@ HttpStructuredCacheService::HandleBatchGetCachePayloads(zen::HttpServerRequest&
return IoHash::Zero;
};
- const bool SkipData = (Policy & CachePolicy::SkipData) == CachePolicy::SkipData;
- const bool SkipAttachments = (Policy & CachePolicy::SkipAttachments) == CachePolicy::SkipAttachments;
- const bool QueryUpstream = m_UpstreamCache && ((Policy & CachePolicy::QueryRemote) == CachePolicy::QueryRemote);
-
const std::string_view Method = BatchRequest["method"sv].AsString();
ZEN_ASSERT(Method == "get-cache-chunks"sv);
CbObjectView Params = BatchRequest["params"sv].AsObjectView();
+ CacheRecordPolicy Policy;
+ CacheRecordPolicy::FromCompactBinary(Params["policy"sv].AsObjectView(), Policy);
+
+ const bool QueryUpstream = m_UpstreamCache && ((Policy.GetRecordPolicy() & CachePolicy::QueryRemote) == CachePolicy::QueryRemote);
+
std::vector<CacheChunkRequest> ChunkRequests;
std::vector<size_t> Missing;