diff options
| author | Per Larsson <[email protected]> | 2021-11-02 10:50:18 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-11-02 10:50:18 +0100 |
| commit | 4b8d4c0e375c729e38bdaadfebf0eaf14f08f5f9 (patch) | |
| tree | d1e6fb1c71a0c8c5e12b2814f309d09d7093c9b3 /zenserver/cache/cachekey.cpp | |
| parent | Merge branch 'main' into zcache-batch (diff) | |
| download | zen-4b8d4c0e375c729e38bdaadfebf0eaf14f08f5f9.tar.xz zen-4b8d4c0e375c729e38bdaadfebf0eaf14f08f5f9.zip | |
Added upstream batch API.
Diffstat (limited to 'zenserver/cache/cachekey.cpp')
| -rw-r--r-- | zenserver/cache/cachekey.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/zenserver/cache/cachekey.cpp b/zenserver/cache/cachekey.cpp new file mode 100644 index 000000000..94ef7fd12 --- /dev/null +++ b/zenserver/cache/cachekey.cpp @@ -0,0 +1,105 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "cachekey.h" + +#include <zencore/string.h> + +namespace zen { + +using namespace std::literals; + +namespace detail { namespace cacheopt { + constexpr std::string_view Local = "local"sv; + constexpr std::string_view Remote = "remote"sv; + constexpr std::string_view Data = "data"sv; + constexpr std::string_view Meta = "meta"sv; + constexpr std::string_view Value = "value"sv; + constexpr std::string_view Attachments = "attachments"sv; +}} // namespace detail::cacheopt + +CachePolicy +ParseQueryCachePolicy(std::string_view QueryPolicy, CachePolicy Default) +{ + if (QueryPolicy.empty()) + { + return Default; + } + + CachePolicy Result = CachePolicy::None; + + ForEachStrTok(QueryPolicy, ',', [&Result](const std::string_view& Token) { + if (Token == detail::cacheopt::Local) + { + Result |= CachePolicy::QueryLocal; + } + if (Token == detail::cacheopt::Remote) + { + Result |= CachePolicy::QueryRemote; + } + return true; + }); + + return Result; +} + +CachePolicy +ParseStoreCachePolicy(std::string_view StorePolicy, CachePolicy Default) +{ + if (StorePolicy.empty()) + { + return Default; + } + + CachePolicy Result = CachePolicy::None; + + ForEachStrTok(StorePolicy, ',', [&Result](const std::string_view& Token) { + if (Token == detail::cacheopt::Local) + { + Result |= CachePolicy::StoreLocal; + } + if (Token == detail::cacheopt::Remote) + { + Result |= CachePolicy::StoreRemote; + } + return true; + }); + + return Result; +} + +CachePolicy +ParseSkipCachePolicy(std::string_view SkipPolicy, CachePolicy Default) +{ + if (SkipPolicy.empty()) + { + return Default; + } + + CachePolicy Result = CachePolicy::None; + + ForEachStrTok(SkipPolicy, ',', [&Result](const std::string_view& Token) { + if (Token == detail::cacheopt::Meta) + { + Result |= CachePolicy::SkipMeta; + } + if (Token == detail::cacheopt::Value) + { + Result |= CachePolicy::SkipValue; + } + if (Token == detail::cacheopt::Attachments) + { + Result |= CachePolicy::SkipAttachments; + } + if (Token == detail::cacheopt::Data) + { + Result |= CachePolicy::SkipData; + } + return true; + }); + + return Result; +} + +CacheKey CacheKey::None = CacheKey{.Bucket = std::string(), .Hash = IoHash()}; + +} // namespace zen |