aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
-rw-r--r--zenserver/cache/structuredcache.cpp41
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();