diff options
| author | Stefan Boberg <[email protected]> | 2021-10-03 21:40:20 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-03 21:40:20 +0200 |
| commit | 132c476c82e82ed7978e82067c9159aaeebbd36f (patch) | |
| tree | ded8d61005361a7d9feb7e5a1aa1153e79d98839 /zenserver/cache/structuredcache.cpp | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen (diff) | |
| parent | http: Moved logic for body suppression to a more central location (diff) | |
| download | zen-132c476c82e82ed7978e82067c9159aaeebbd36f.tar.xz zen-132c476c82e82ed7978e82067c9159aaeebbd36f.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 8ab0276c5..d6174caf6 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -200,8 +200,10 @@ HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request) { std::string_view Key = Request.RelativeUri(); - if (Key.empty()) + if (Key.empty() || Key == "stats.json") { + $.Cancel(); + return HandleStatusRequest(Request); } @@ -270,10 +272,6 @@ HttpStructuredCacheService::HandleCacheRecordRequest(HttpServerRequest& Request, case kHead: case kGet: { - if (Verb == kHead) - { - Request.SetSuppressResponseBody(); - } HandleGetCacheRecord(Request, Ref, Policy); } break; @@ -418,10 +416,17 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request if (ValidationResult != CbValidateError::None) { ZEN_WARN("GET - '{}/{}' '{}' FAILED, invalid compact binary object", Ref.BucketSegment, Ref.HashKey, ToString(AcceptType)); + m_CacheStats.MissCount++; return Request.WriteResponse(HttpResponseCode::NotFound, HttpContentType::kText, "Invalid cache record"sv); } - const bool SkipAttachments = zen::CachePolicy::SkipAttachments == (Policy & zen::CachePolicy::SkipAttachments); + if ((Policy & CachePolicy::SkipData) == CachePolicy::SkipData) + { + m_CacheStats.HitCount++; + return Request.WriteResponse(HttpResponseCode::OK); + } + + const bool SkipAttachments = (Policy & CachePolicy::SkipAttachments) == CachePolicy::SkipAttachments; uint32_t AttachmentCount = 0; uint32_t ValidCount = 0; uint64_t AttachmentBytes = 0ull; @@ -487,7 +492,14 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request m_CacheStats.UpstreamHitCount++; } - Request.WriteResponse(HttpResponseCode::OK, Value.Value.GetContentType(), Value.Value); + if ((Policy & CachePolicy::SkipData) == CachePolicy::SkipData) + { + Request.WriteResponse(HttpResponseCode::OK); + } + else + { + Request.WriteResponse(HttpResponseCode::OK, Value.Value.GetContentType(), Value.Value); + } } } @@ -676,10 +688,6 @@ HttpStructuredCacheService::HandleCachePayloadRequest(HttpServerRequest& Request case kHead: case kGet: { - if (Verb == kHead) - { - Request.SetSuppressResponseBody(); - } HandleGetCachePayload(Request, Ref, Policy); } break; @@ -740,7 +748,14 @@ HttpStructuredCacheService::HandleGetCachePayload(zen::HttpServerRequest& Reques m_CacheStats.UpstreamHitCount++; } - Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Payload); + if ((Policy & CachePolicy::SkipData) == CachePolicy::SkipData) + { + Request.WriteResponse(HttpResponseCode::OK); + } + else + { + Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Payload); + } } void @@ -868,7 +883,9 @@ HttpStructuredCacheService::HandleStatusRequest(zen::HttpServerRequest& Request) const uint64_t TotalCount = HitCount + MissCount; Cbo.BeginObject("cache"); + Cbo << "hits" << HitCount << "misses" << MissCount; Cbo << "hit_ratio" << (TotalCount > 0 ? (double(HitCount) / double(TotalCount) * 100.0) : 0.0); + Cbo << "upstream_hits" << m_CacheStats.UpstreamHitCount; Cbo << "upstream_ratio" << (HitCount > 0 ? (double(UpstreamHitCount) / double(HitCount)) * 100.0 : 0.0); Cbo.EndObject(); |