diff options
| author | mattpetersepic <[email protected]> | 2022-01-26 18:45:04 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-26 18:45:04 -0700 |
| commit | 09f2ac4d9aaea0107af8fbd6a41c2d3fe3e450ba (patch) | |
| tree | 41bc55af44f16fafa674c7e8c21d56fec7c79d53 /zenutil/cache/cachepolicy.cpp | |
| parent | Implement SkipData,QueryLocal,StoreLocal for GET-verb CacheGet requests (#39) (diff) | |
| download | zen-09f2ac4d9aaea0107af8fbd6a41c2d3fe3e450ba.tar.xz zen-09f2ac4d9aaea0107af8fbd6a41c2d3fe3e450ba.zip | |
Implement SkipData,QueryLocal,StoreLocal for HandleRpcGetCacheRecords (#41)
* Implement SkipData,QueryLocal,StoreLocal for HandleRpcGetCacheRecords.
Diffstat (limited to 'zenutil/cache/cachepolicy.cpp')
| -rw-r--r-- | zenutil/cache/cachepolicy.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/zenutil/cache/cachepolicy.cpp b/zenutil/cache/cachepolicy.cpp index ba345485a..3bf7a0c67 100644 --- a/zenutil/cache/cachepolicy.cpp +++ b/zenutil/cache/cachepolicy.cpp @@ -4,6 +4,7 @@ #include <zencore/compactbinary.h> #include <zencore/compactbinarybuilder.h> +#include <zencore/enumflags.h> #include <zencore/string.h> #include <algorithm> @@ -206,6 +207,25 @@ CacheRecordPolicy::Load(CbObjectView Object, CachePolicy DefaultPolicy) return Builder.Build(); } +CacheRecordPolicy +CacheRecordPolicy::ConvertToUpstream() const +{ + auto DownstreamToUpstream = [](CachePolicy P) { + // Remote|Local -> Set Remote + // Delete Skip Flags + // Maintain Remaining Flags + return (EnumHasAllFlags(P, CachePolicy::QueryRemote) ? CachePolicy::QueryLocal : CachePolicy::None) | + (EnumHasAllFlags(P, CachePolicy::StoreRemote) ? CachePolicy::StoreLocal : CachePolicy::None) | + (P & ~(CachePolicy::SkipData | CachePolicy::SkipMeta)); + }; + CacheRecordPolicyBuilder Builder(DownstreamToUpstream(GetDefaultValuePolicy())); + for (const CacheValuePolicy& ValuePolicy : GetValuePolicies()) + { + Builder.AddValuePolicy(ValuePolicy.Id, DownstreamToUpstream(ValuePolicy.Policy)); + } + return Builder.Build(); +} + void CacheRecordPolicyBuilder::AddValuePolicy(const CacheValuePolicy& Policy) { |