aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/cachekey.cpp
blob: 94ef7fd125abee857cd4a5e62304d36a373a8e9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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