aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-11-12 11:08:53 +0100
committerPer Larsson <[email protected]>2021-11-12 11:08:53 +0100
commit3faf0b57c625152a8facfca1c4995bd9edc95707 (patch)
tree0ae1ff078147091bafb7f5f4799943cebd0a7f50
parentChanged from batch to RPC. (diff)
downloadzen-3faf0b57c625152a8facfca1c4995bd9edc95707.tar.xz
zen-3faf0b57c625152a8facfca1c4995bd9edc95707.zip
Movec cache utility types to zenutil and fixed unit tests.
-rw-r--r--zenserver-test/zenserver-test.cpp166
-rw-r--r--zenserver/cache/structuredcache.cpp49
-rw-r--r--zenserver/upstream/upstreamcache.h3
-rw-r--r--zenserver/zenserver.vcxproj2
-rw-r--r--zenserver/zenserver.vcxproj.filters6
-rw-r--r--zenutil/cache/cachekey.cpp9
-rw-r--r--zenutil/cache/cachepolicy.cpp (renamed from zenserver/cache/cachekey.cpp)4
-rw-r--r--zenutil/include/zenutil/cache/cache.h6
-rw-r--r--zenutil/include/zenutil/cache/cachekey.h83
-rw-r--r--zenutil/include/zenutil/cache/cachepolicy.h (renamed from zenserver/cache/cachekey.h)73
-rw-r--r--zenutil/zenutil.vcxproj5
-rw-r--r--zenutil/zenutil.vcxproj.filters20
12 files changed, 239 insertions, 187 deletions
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp
index fd1c010be..a5cfabe08 100644
--- a/zenserver-test/zenserver-test.cpp
+++ b/zenserver-test/zenserver-test.cpp
@@ -20,6 +20,7 @@
#include <zenhttp/httpclient.h>
#include <zenhttp/httpshared.h>
#include <zenhttp/zenhttp.h>
+#include <zenutil/cache/cache.h>
#include <zenutil/zenserverprocess.h>
#if ZEN_USE_MIMALLOC
@@ -1891,9 +1892,7 @@ TEST_CASE("zcache.batch")
{
using namespace std::literals;
- auto CreateCacheKey = [](uint32_t Id) -> zen::IoHash { return zen::IoHash::HashBuffer(&Id, sizeof(uint32_t)); };
-
- auto CreateCacheRecord = [](uint32_t Key, size_t PayloadSize) -> zen::CbPackage {
+ auto CreateCacheRecord = [](const zen::CacheKey& CacheKey, size_t PayloadSize) -> zen::CbPackage {
std::vector<uint8_t> Data;
Data.resize(PayloadSize);
for (size_t Idx = 0; Idx < PayloadSize; ++Idx)
@@ -1901,11 +1900,13 @@ TEST_CASE("zcache.batch")
Data[Idx] = Idx % 255;
}
- auto Compressed = zen::CompressedBuffer::Compress(SharedBuffer::MakeView(Data.data(), Data.size()));
- zen::CbAttachment Attachment(Compressed);
+ zen::CbAttachment Attachment(zen::CompressedBuffer::Compress(SharedBuffer::MakeView(Data.data(), Data.size())));
zen::CbObjectWriter CacheRecord;
- CacheRecord << "key" << Key << "data" << Attachment;
+ CacheRecord.BeginObject("CacheKey"sv);
+ CacheRecord << "Bucket"sv << CacheKey.Bucket << "Hash"sv << CacheKey.Hash;
+ CacheRecord.EndObject();
+ CacheRecord << "Data"sv << Attachment;
zen::CbPackage Package;
Package.SetObject(CacheRecord.Save());
@@ -1931,18 +1932,20 @@ TEST_CASE("zcache.batch")
Inst.SpawnServer(PortNumber);
Inst.WaitUntilReady();
- const std::string_view Bucket = "mastodon"sv;
- const uint32_t BatchCount = 128;
+ std::vector<zen::CacheKey> CacheKeys;
- // Create cach records
+ // Create some cache records
{
- for (uint32_t Key = 1; Key <= BatchCount; ++Key)
+ for (uint32_t Key = 1; Key <= 128; ++Key)
{
- const IoHash CacheKey = CreateCacheKey(Key);
- CbPackage CacheRecord = CreateCacheRecord(Key, 4096);
- IoBuffer Payload = ToIoBuffer(CacheRecord);
+ const CacheKey CacheKey = zen::CacheKey::Create("mastodon"sv, zen::IoHash::HashBuffer(&Key, sizeof uint32_t));
+ CbPackage CacheRecord = CreateCacheRecord(CacheKey, 1024);
+
+ CacheKeys.push_back(CacheKey);
- cpr::Response Result = cpr::Put(cpr::Url{"{}/{}/{}"_format(BaseUri, Bucket, CacheKey)},
+ IoBuffer Payload = ToIoBuffer(CacheRecord);
+
+ cpr::Response Result = cpr::Put(cpr::Url{"{}/{}/{}"_format(BaseUri, CacheKey.Bucket, CacheKey.Hash)},
cpr::Body{(const char*)Payload.Data(), Payload.Size()},
cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}});
@@ -1954,27 +1957,26 @@ TEST_CASE("zcache.batch")
{
CbObjectWriter BatchRequest;
- BatchRequest << "method"
- << "get-cache-records";
+ BatchRequest << "Method"sv
+ << "GetCacheRecords"sv;
- BatchRequest.BeginObject("params");
- BatchRequest.BeginArray("cachekeys"sv);
+ BatchRequest.BeginObject("Params"sv);
- for (uint32_t Key = 1; Key <= BatchCount; ++Key)
+ BatchRequest.BeginArray("CacheKeys"sv);
+ for (const CacheKey& Key : CacheKeys)
{
- const IoHash CacheKey = CreateCacheKey(Key);
BatchRequest.BeginObject();
- BatchRequest << "bucket"sv << Bucket << "hash" << CacheKey;
+ BatchRequest << "Bucket"sv << Key.Bucket << "Hash"sv << Key.Hash;
BatchRequest.EndObject();
}
-
BatchRequest.EndArray();
+
BatchRequest.EndObject();
zen::BinaryWriter Payload;
BatchRequest.Save(Payload);
- cpr::Response Result = cpr::Post(cpr::Url{"{}/$batch"_format(BaseUri)},
+ cpr::Response Result = cpr::Post(cpr::Url{"{}/$rpc"_format(BaseUri)},
cpr::Header{{"Content-Type", "application/x-ue-cb"}, {"Accept", "application/x-ue-cbpkg"}},
cpr::Body{(const char*)Payload.GetData(), Payload.GetSize()});
@@ -1985,24 +1987,26 @@ TEST_CASE("zcache.batch")
const bool Ok = Package.TryLoad(Response);
CHECK(Ok);
- size_t ReturnCount = 0;
-
+ size_t ReturnCount = 0;
CbObjectView BatchResponse = Package.GetObject();
- for (uint32_t ExpectedKey = 1; CbFieldView ResponseView : BatchResponse["result"])
+
+ for (size_t Index = 0; CbFieldView RecordView : BatchResponse["Result"])
{
- CbObjectView Response = ResponseView.AsObjectView();
- const uint32_t Key = Response["key"sv].AsUInt32();
- const IoHash AttachmentHash = Response["data"sv].AsHash();
+ const CacheKey& ExpectedKey = CacheKeys[Index++];
+
+ CbObjectView RecordObj = RecordView.AsObjectView();
+ CbObjectView KeyObj = RecordObj["CacheKey"sv].AsObjectView();
+ const CacheKey Key = CacheKey::Create(KeyObj["Bucket"sv].AsString(), KeyObj["Hash"].AsHash());
+ const IoHash AttachmentHash = RecordObj["Data"sv].AsHash();
const CbAttachment* Attachment = Package.FindAttachment(AttachmentHash);
CHECK(Key == ExpectedKey);
CHECK(Attachment != nullptr);
- ExpectedKey++;
ReturnCount++;
}
- CHECK(ReturnCount == BatchCount);
+ CHECK(ReturnCount == CacheKeys.size());
}
}
@@ -2017,17 +2021,20 @@ TEST_CASE("zcache.batch")
Inst.SpawnServer(PortNumber);
Inst.WaitUntilReady();
- const std::string_view Bucket = "mastodon"sv;
+ std::vector<zen::CacheKey> CacheKeys;
// Create some cache records
{
- for (uint32_t Key = 1; Key <= 5; ++Key)
+ for (uint32_t Key = 1; Key <= 4; ++Key)
{
- const IoHash CacheKey = CreateCacheKey(Key);
- CbPackage CacheRecord = CreateCacheRecord(Key, 4096);
- IoBuffer Payload = ToIoBuffer(CacheRecord);
+ const CacheKey CacheKey = zen::CacheKey::Create("mastodon"sv, zen::IoHash::HashBuffer(&Key, sizeof uint32_t));
+ CbPackage CacheRecord = CreateCacheRecord(CacheKey, 1024);
+
+ CacheKeys.push_back(CacheKey);
- cpr::Response Result = cpr::Put(cpr::Url{"{}/{}/{}"_format(BaseUri, Bucket, CacheKey)},
+ IoBuffer Payload = ToIoBuffer(CacheRecord);
+
+ cpr::Response Result = cpr::Put(cpr::Url{"{}/{}/{}"_format(BaseUri, CacheKey.Bucket, CacheKey.Hash)},
cpr::Body{(const char*)Payload.Data(), Payload.Size()},
cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}});
@@ -2035,37 +2042,37 @@ TEST_CASE("zcache.batch")
}
}
+ // Get all records with every other missing
{
CbObjectWriter BatchRequest;
- BatchRequest << "method"
- << "get-cache-records";
-
- BatchRequest.BeginObject("params");
- BatchRequest.BeginArray("cachekeys"sv);
+ BatchRequest << "Method"sv
+ << "GetCacheRecords"sv;
- BatchRequest.BeginObject();
- BatchRequest << "bucket"sv << Bucket << "hash" << CreateCacheKey(1);
- BatchRequest.EndObject();
- BatchRequest.BeginObject();
- BatchRequest << "bucket"sv << Bucket << "hash" << CreateCacheKey(11); // Missing
- BatchRequest.EndObject();
- BatchRequest.BeginObject();
- BatchRequest << "bucket"sv << Bucket << "hash" << CreateCacheKey(2);
- BatchRequest.EndObject();
- BatchRequest.BeginObject();
- BatchRequest << "bucket"sv << Bucket << "hash" << CreateCacheKey(22); // Missing
- BatchRequest.EndObject();
+ BatchRequest.BeginObject("Params"sv);
+ BatchRequest.BeginArray("CacheKeys"sv);
+ for (const CacheKey& Key : CacheKeys)
+ {
+ BatchRequest.BeginObject();
+ BatchRequest << "Bucket"sv << Key.Bucket << "Hash"sv << Key.Hash;
+ BatchRequest.EndObject();
+ BatchRequest.BeginObject();
+ BatchRequest << "Bucket"sv
+ << "missing"sv
+ << "Hash"sv << Key.Hash;
+ BatchRequest.EndObject();
+ }
BatchRequest.EndArray();
+
BatchRequest.EndObject();
- zen::BinaryWriter Body;
- BatchRequest.Save(Body);
+ zen::BinaryWriter Payload;
+ BatchRequest.Save(Payload);
- cpr::Response Result = cpr::Post(cpr::Url{"{}/$batch"_format(BaseUri)},
+ cpr::Response Result = cpr::Post(cpr::Url{"{}/$rpc"_format(BaseUri)},
cpr::Header{{"Content-Type", "application/x-ue-cb"}, {"Accept", "application/x-ue-cbpkg"}},
- cpr::Body{(const char*)Body.GetData(), Body.GetSize()});
+ cpr::Body{(const char*)Payload.GetData(), Payload.GetSize()});
CHECK(Result.status_code == 200);
@@ -2075,35 +2082,36 @@ TEST_CASE("zcache.batch")
CHECK(Ok);
CbObjectView BatchResponse = Package.GetObject();
- CbArrayView CacheRecords = BatchResponse["result"sv].AsArrayView();
- auto It = CacheRecords.CreateViewIterator();
+ size_t KeyIndex = 0;
+ size_t ReturnCount = 0;
+
+ for (size_t Index = 0; CbFieldView RecordView : BatchResponse["Result"])
{
- CbObjectView CacheRecord = It.AsObjectView();
- const uint32_t Key = CacheRecord["key"sv].AsUInt32();
- const IoHash AttachmentHash = CacheRecord["data"sv].AsHash();
- const CbAttachment* Attachment = Package.FindAttachment(AttachmentHash);
+ const bool Missing = Index++ % 2 != 0;
- CHECK(Key == 1);
- CHECK(Attachment != nullptr);
- }
+ if (Missing)
+ {
+ CHECK(RecordView.IsNull());
+ }
+ else
+ {
+ const CacheKey& ExpectedKey = CacheKeys[KeyIndex++];
- It++;
- CHECK(It.IsNull());
+ CbObjectView RecordObj = RecordView.AsObjectView();
+ CbObjectView KeyObj = RecordObj["CacheKey"sv].AsObjectView();
+ const CacheKey Key = CacheKey::Create(KeyObj["Bucket"sv].AsString(), KeyObj["Hash"].AsHash());
+ const IoHash AttachmentHash = RecordObj["Data"sv].AsHash();
+ const CbAttachment* Attachment = Package.FindAttachment(AttachmentHash);
- It++;
- {
- CbObjectView CacheRecord = It.AsObjectView();
- const uint32_t Key = CacheRecord["key"sv].AsUInt32();
- const IoHash AttachmentHash = CacheRecord["data"sv].AsHash();
- const CbAttachment* Attachment = Package.FindAttachment(AttachmentHash);
+ CHECK(Key == ExpectedKey);
+ CHECK(Attachment != nullptr);
+ }
- CHECK(Key == 2);
- CHECK(Attachment != nullptr);
+ ReturnCount++;
}
- It++;
- CHECK(It.IsNull());
+ CHECK(ReturnCount == (CacheKeys.size() * 2));
}
}
}
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index e78e583aa..1b6406562 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -11,8 +11,9 @@
#include <zencore/timer.h>
#include <zenhttp/httpserver.h>
#include <zenstore/CAS.h>
+#include <zenutil/cache/cache.h>
-#include "cachekey.h"
+//#include "cachekey.h"
#include "monitoring/httpstats.h"
#include "structuredcache.h"
#include "structuredcachestore.h"
@@ -796,15 +797,15 @@ HttpStructuredCacheService::HandleRpcRequest(zen::HttpServerRequest& Request)
}
Request.WriteResponseAsync(
- [this, BatchRequest = zen::LoadCompactBinaryObject(Request.ReadPayload())](HttpServerRequest& AsyncRequest) {
- const std::string_view Method = BatchRequest["Method"sv].AsString();
+ [this, RpcRequest = zen::LoadCompactBinaryObject(Request.ReadPayload())](HttpServerRequest& AsyncRequest) {
+ const std::string_view Method = RpcRequest["Method"sv].AsString();
if (Method == "GetCacheRecords"sv)
{
- HandleRpcGetCacheRecords(AsyncRequest, BatchRequest);
+ HandleRpcGetCacheRecords(AsyncRequest, RpcRequest);
}
else if (Method == "GetCachePayloads"sv)
{
- HandleRpcGetCachePayloads(AsyncRequest, BatchRequest);
+ HandleRpcGetCachePayloads(AsyncRequest, RpcRequest);
}
else
{
@@ -820,18 +821,18 @@ HttpStructuredCacheService::HandleRpcRequest(zen::HttpServerRequest& Request)
}
void
-HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView BatchRequest)
+HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView RpcRequest)
{
using namespace fmt::literals;
- CbPackage BatchResponse;
+ CbPackage RpcResponse;
CacheRecordPolicy Policy;
- CbObjectView Params = BatchRequest["Params"sv].AsObjectView();
+ CbObjectView Params = RpcRequest["Params"sv].AsObjectView();
std::vector<CacheKey> CacheKeys;
std::vector<IoBuffer> CacheValues;
std::vector<size_t> UpstreamRequests;
- ZEN_ASSERT(BatchRequest["Method"sv].AsString() == "GetCacheRecords"sv);
+ ZEN_ASSERT(RpcRequest["Method"sv].AsString() == "GetCacheRecords"sv);
CacheRecordPolicy::Load(Params["Policy"sv].AsObjectView(), Policy);
@@ -860,10 +861,10 @@ HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Req
if (!SkipAttachments)
{
- CacheRecord.IterateAttachments([this, &BatchResponse](CbFieldView AttachmentHash) {
+ CacheRecord.IterateAttachments([this, &RpcResponse](CbFieldView AttachmentHash) {
if (IoBuffer Chunk = m_CidStore.FindChunkByCid(AttachmentHash.AsHash()))
{
- BatchResponse.AddAttachment(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(Chunk))));
+ RpcResponse.AddAttachment(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(Chunk))));
}
});
}
@@ -893,7 +894,7 @@ HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Req
if (!UpstreamRequests.empty() && m_UpstreamCache)
{
const auto OnCacheRecordGetComplete =
- [this, &CacheKeys, &CacheValues, &BatchResponse, SkipAttachments](CacheRecordGetCompleteParams&& Params) {
+ [this, &CacheKeys, &CacheValues, &RpcResponse, SkipAttachments](CacheRecordGetCompleteParams&& Params) {
if (Params.Record)
{
Params.Record.IterateAttachments([&](CbFieldView AttachmentHash) {
@@ -905,7 +906,7 @@ HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Req
if (!SkipAttachments)
{
- BatchResponse.AddAttachment(CbAttachment(Compressed));
+ RpcResponse.AddAttachment(CbAttachment(Compressed));
}
}
}
@@ -917,6 +918,7 @@ HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Req
NiceBytes(Params.Record.GetView().GetSize()),
ToString(HttpContentType::kCbObject));
+ ZEN_ASSERT(Params.KeyIndex < CacheValues.size());
CacheValues[Params.KeyIndex] = IoBufferBuilder::MakeCloneFromMemory(Params.Record.GetView());
m_CacheStats.HitCount++;
m_CacheStats.UpstreamHitCount++;
@@ -948,10 +950,10 @@ HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Req
}
ResponseObject.EndArray();
- BatchResponse.SetObject(ResponseObject.Save());
+ RpcResponse.SetObject(ResponseObject.Save());
BinaryWriter MemStream;
- BatchResponse.Save(MemStream);
+ RpcResponse.Save(MemStream);
Request.WriteResponse(HttpResponseCode::OK,
HttpContentType::kCbPackage,
@@ -959,16 +961,16 @@ HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& Req
}
void
-HttpStructuredCacheService::HandleRpcGetCachePayloads(zen::HttpServerRequest& Request, CbObjectView BatchRequest)
+HttpStructuredCacheService::HandleRpcGetCachePayloads(zen::HttpServerRequest& Request, CbObjectView RpcRequest)
{
using namespace fmt::literals;
- ZEN_ASSERT(BatchRequest["Method"sv].AsString() == "GetCachePayloads"sv);
+ ZEN_ASSERT(RpcRequest["Method"sv].AsString() == "GetCachePayloads"sv);
std::vector<CacheChunkRequest> ChunkRequests;
std::vector<size_t> UpstreamRequests;
std::vector<IoBuffer> Chunks;
- CbObjectView Params = BatchRequest["Params"sv].AsObjectView();
+ CbObjectView Params = RpcRequest["Params"sv].AsObjectView();
for (CbFieldView RequestView : Params["ChunkRequests"sv])
{
@@ -1029,7 +1031,7 @@ HttpStructuredCacheService::HandleRpcGetCachePayloads(zen::HttpServerRequest& Re
CurrentKey = ChunkRequest.Key;
ZenCacheValue CacheValue;
- if (m_CacheStore.Get(ChunkRequest.Key.Bucket, ChunkRequest.Key.Hash, CacheValue))
+ if (m_CacheStore.Get(CurrentKey.Bucket, CurrentKey.Hash, CacheValue))
{
CurrentRecordBuffer = CacheValue.Value;
}
@@ -1094,6 +1096,7 @@ HttpStructuredCacheService::HandleRpcGetCachePayloads(zen::HttpServerRequest& Re
NiceBytes(Params.Payload.GetSize()),
"UPSTREAM");
+ ZEN_ASSERT(Params.RequestIndex < Chunks.size());
Chunks[Params.RequestIndex] = std::move(Params.Payload);
m_CacheStats.HitCount++;
@@ -1109,7 +1112,7 @@ HttpStructuredCacheService::HandleRpcGetCachePayloads(zen::HttpServerRequest& Re
m_UpstreamCache->GetCachePayloads(ChunkRequests, UpstreamRequests, std::move(OnCachePayloadGetComplete));
}
- CbPackage BatchResponse;
+ CbPackage RpcResponse;
CbObjectWriter ResponseObject;
ResponseObject.BeginArray("Result"sv);
@@ -1119,7 +1122,7 @@ HttpStructuredCacheService::HandleRpcGetCachePayloads(zen::HttpServerRequest& Re
if (Chunks[ChunkIndex])
{
ResponseObject << ChunkRequests[ChunkIndex].ChunkId;
- BatchResponse.AddAttachment(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(std::move(Chunks[ChunkIndex])))));
+ RpcResponse.AddAttachment(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(std::move(Chunks[ChunkIndex])))));
}
else
{
@@ -1128,10 +1131,10 @@ HttpStructuredCacheService::HandleRpcGetCachePayloads(zen::HttpServerRequest& Re
}
ResponseObject.EndArray();
- BatchResponse.SetObject(ResponseObject.Save());
+ RpcResponse.SetObject(ResponseObject.Save());
BinaryWriter MemStream;
- BatchResponse.Save(MemStream);
+ RpcResponse.Save(MemStream);
Request.WriteResponse(HttpResponseCode::OK,
HttpContentType::kCbPackage,
diff --git a/zenserver/upstream/upstreamcache.h b/zenserver/upstream/upstreamcache.h
index 681d8e96f..e5c3521b9 100644
--- a/zenserver/upstream/upstreamcache.h
+++ b/zenserver/upstream/upstreamcache.h
@@ -2,11 +2,10 @@
#pragma once
-#include "cache/cachekey.h"
-
#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
#include <zencore/zencore.h>
+#include <zenutil/cache/cache.h>
#include <atomic>
#include <chrono>
diff --git a/zenserver/zenserver.vcxproj b/zenserver/zenserver.vcxproj
index d90dd009a..d954d3f8d 100644
--- a/zenserver/zenserver.vcxproj
+++ b/zenserver/zenserver.vcxproj
@@ -105,7 +105,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="admin\admin.h" />
- <ClInclude Include="cache\cachekey.h" />
<ClInclude Include="cache\structuredcache.h" />
<ClInclude Include="cache\structuredcachestore.h" />
<ClInclude Include="compute\apply.h" />
@@ -132,7 +131,6 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="admin\admin.cpp" />
- <ClCompile Include="cache\cachekey.cpp" />
<ClCompile Include="cache\structuredcache.cpp" />
<ClCompile Include="cache\structuredcachestore.cpp" />
<ClCompile Include="compute\apply.cpp" />
diff --git a/zenserver/zenserver.vcxproj.filters b/zenserver/zenserver.vcxproj.filters
index ae5411afb..04c6267ba 100644
--- a/zenserver/zenserver.vcxproj.filters
+++ b/zenserver/zenserver.vcxproj.filters
@@ -41,9 +41,6 @@
<ClInclude Include="experimental\vfs.h" />
<ClInclude Include="monitoring\httpstats.h" />
<ClInclude Include="monitoring\httpstatus.h" />
- <ClInclude Include="cache\cachekey.h">
- <Filter>cache</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="zenserver.cpp" />
@@ -79,9 +76,6 @@
<ClCompile Include="experimental\vfs.cpp" />
<ClCompile Include="monitoring\httpstats.cpp" />
<ClCompile Include="monitoring\httpstatus.cpp" />
- <ClCompile Include="cache\cachekey.cpp">
- <Filter>cache</Filter>
- </ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="cache">
diff --git a/zenutil/cache/cachekey.cpp b/zenutil/cache/cachekey.cpp
new file mode 100644
index 000000000..545b47f11
--- /dev/null
+++ b/zenutil/cache/cachekey.cpp
@@ -0,0 +1,9 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include <zenutil/cache/cachekey.h>
+
+namespace zen {
+
+const CacheKey CacheKey::Empty = CacheKey{.Bucket = std::string(), .Hash = IoHash()};
+
+} // namespace zen
diff --git a/zenserver/cache/cachekey.cpp b/zenutil/cache/cachepolicy.cpp
index 2ead9ac58..968f6aa53 100644
--- a/zenserver/cache/cachekey.cpp
+++ b/zenutil/cache/cachepolicy.cpp
@@ -1,6 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
-#include "cachekey.h"
+#include <zenutil/cache/cachepolicy.h>
#include <zencore/compactbinary.h>
#include <zencore/compactbinarybuilder.h>
@@ -158,6 +158,4 @@ CacheRecordPolicy::Save(const CacheRecordPolicy& Policy, CbWriter& Writer)
}
}
-const CacheKey CacheKey::Empty = CacheKey{.Bucket = std::string(), .Hash = IoHash()};
-
} // namespace zen
diff --git a/zenutil/include/zenutil/cache/cache.h b/zenutil/include/zenutil/cache/cache.h
new file mode 100644
index 000000000..c62ea6212
--- /dev/null
+++ b/zenutil/include/zenutil/cache/cache.h
@@ -0,0 +1,6 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <zenutil/cache/cachepolicy.h>
+#include <zenutil/cache/cachekey.h>
diff --git a/zenutil/include/zenutil/cache/cachekey.h b/zenutil/include/zenutil/cache/cachekey.h
new file mode 100644
index 000000000..fb36c7759
--- /dev/null
+++ b/zenutil/include/zenutil/cache/cachekey.h
@@ -0,0 +1,83 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <zencore/iohash.h>
+#include <zencore/string.h>
+#include <zencore/uid.h>
+
+#include <zenutil/cache/cachepolicy.h>
+
+namespace zen {
+
+struct CacheKey
+{
+ std::string Bucket;
+ IoHash Hash;
+
+ static CacheKey Create(std::string_view Bucket, const IoHash& Hash) { return {.Bucket = ToLower(Bucket), .Hash = Hash}; }
+
+ static const CacheKey Empty;
+};
+
+inline bool
+operator==(const CacheKey& A, const CacheKey& B)
+{
+ return A.Bucket == B.Bucket && A.Hash == B.Hash;
+}
+
+inline bool
+operator!=(const CacheKey& A, const CacheKey& B)
+{
+ return A.Bucket != B.Bucket || A.Hash != B.Hash;
+}
+
+inline bool
+operator<(const CacheKey& A, const CacheKey& B)
+{
+ const std::string& BucketA = A.Bucket;
+ const std::string& BucketB = B.Bucket;
+ return BucketA == BucketB ? A.Hash < B.Hash : BucketA < BucketB;
+}
+
+struct CacheChunkRequest
+{
+ CacheKey Key;
+ IoHash ChunkId;
+ Oid PayloadId;
+ uint64_t RawOffset = 0ull;
+ uint64_t RawSize = ~uint64_t(0);
+ CachePolicy Policy = CachePolicy::Default;
+};
+
+inline bool
+operator<(const CacheChunkRequest& A, const CacheChunkRequest& B)
+{
+ if (A.Key < B.Key)
+ {
+ return true;
+ }
+ if (B.Key < A.Key)
+ {
+ return false;
+ }
+ if (A.ChunkId < B.ChunkId)
+ {
+ return true;
+ }
+ if (B.ChunkId < A.ChunkId)
+ {
+ return false;
+ }
+ if (A.PayloadId < B.PayloadId)
+ {
+ return true;
+ }
+ if (B.PayloadId < A.PayloadId)
+ {
+ return false;
+ }
+ return A.RawOffset < B.RawOffset;
+}
+
+} // namespace zen
diff --git a/zenserver/cache/cachekey.h b/zenutil/include/zenutil/cache/cachepolicy.h
index c32f7ed87..da0db435c 100644
--- a/zenserver/cache/cachekey.h
+++ b/zenutil/include/zenutil/cache/cachepolicy.h
@@ -2,11 +2,10 @@
#pragma once
-#include <zencore/iohash.h>
#include <zencore/string.h>
#include <zencore/uid.h>
-#include <gsl/gsl-lite.hpp>
+#include <gsl/gsl-lite.hpp>
#include <unordered_map>
namespace zen {
@@ -62,74 +61,4 @@ private:
PayloadPolicyMap m_PayloadPolicies;
};
-struct CacheKey
-{
- std::string Bucket;
- IoHash Hash;
-
- static CacheKey Create(std::string_view Bucket, const IoHash& Hash) { return {.Bucket = ToLower(Bucket), .Hash = Hash}; }
-
- static const CacheKey Empty;
-};
-
-inline bool
-operator==(const CacheKey& A, const CacheKey& B)
-{
- return A.Bucket == B.Bucket && A.Hash == B.Hash;
-}
-
-inline bool
-operator!=(const CacheKey& A, const CacheKey& B)
-{
- return A.Bucket != B.Bucket || A.Hash != B.Hash;
-}
-
-inline bool
-operator<(const CacheKey& A, const CacheKey& B)
-{
- const std::string& BucketA = A.Bucket;
- const std::string& BucketB = B.Bucket;
- return BucketA == BucketB ? A.Hash < B.Hash : BucketA < BucketB;
-}
-
-struct CacheChunkRequest
-{
- CacheKey Key;
- IoHash ChunkId;
- Oid PayloadId;
- uint64_t RawOffset = 0ull;
- uint64_t RawSize = ~uint64_t(0);
- CachePolicy Policy = CachePolicy::Default;
-};
-
-inline bool
-operator<(const CacheChunkRequest& A, const CacheChunkRequest& B)
-{
- if (A.Key < B.Key)
- {
- return true;
- }
- if (B.Key < A.Key)
- {
- return false;
- }
- if (A.ChunkId < B.ChunkId)
- {
- return true;
- }
- if (B.ChunkId < A.ChunkId)
- {
- return false;
- }
- if (A.PayloadId < B.PayloadId)
- {
- return true;
- }
- if (B.PayloadId < A.PayloadId)
- {
- return false;
- }
- return A.RawOffset < B.RawOffset;
-}
-
} // namespace zen
diff --git a/zenutil/zenutil.vcxproj b/zenutil/zenutil.vcxproj
index 3bf6111f7..f5db7c5b0 100644
--- a/zenutil/zenutil.vcxproj
+++ b/zenutil/zenutil.vcxproj
@@ -97,9 +97,14 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="cache\cachekey.cpp" />
+ <ClCompile Include="cache\cachepolicy.cpp" />
<ClCompile Include="zenserverprocess.cpp" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="include\zenutil\cache\cache.h" />
+ <ClInclude Include="include\zenutil\cache\cachekey.h" />
+ <ClInclude Include="include\zenutil\cache\cachepolicy.h" />
<ClInclude Include="include\zenutil\zenserverprocess.h" />
</ItemGroup>
<ItemGroup>
diff --git a/zenutil/zenutil.vcxproj.filters b/zenutil/zenutil.vcxproj.filters
index 9952e7159..368a827c2 100644
--- a/zenutil/zenutil.vcxproj.filters
+++ b/zenutil/zenutil.vcxproj.filters
@@ -2,11 +2,31 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="zenserverprocess.cpp" />
+ <ClCompile Include="cache\cachekey.cpp">
+ <Filter>cache</Filter>
+ </ClCompile>
+ <ClCompile Include="cache\cachepolicy.cpp">
+ <Filter>cache</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\zenutil\zenserverprocess.h" />
+ <ClInclude Include="include\zenutil\cache\cache.h">
+ <Filter>cache</Filter>
+ </ClInclude>
+ <ClInclude Include="include\zenutil\cache\cachekey.h">
+ <Filter>cache</Filter>
+ </ClInclude>
+ <ClInclude Include="include\zenutil\cache\cachepolicy.h">
+ <Filter>cache</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="xmake.lua" />
</ItemGroup>
+ <ItemGroup>
+ <Filter Include="cache">
+ <UniqueIdentifier>{a441c536-6a01-4ac4-85a0-2667c95027d0}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
</Project> \ No newline at end of file