private bool PublishResponseContent(HttpRequestMessage request, HttpResponseMessage response, long responseHash)
{
if (!ClientCacheEnabled)
return true;
// See if client's version of cached resource is up to date
foreach (EntityTagHeaderValue headerValue in request.Headers.IfNoneMatch)
{
long requestHash;
if (long.TryParse(headerValue.Tag?.Substring(1, headerValue.Tag.Length - 2), out requestHash) && responseHash == requestHash)
{
response.StatusCode = HttpStatusCode.NotModified;
return false;
}
}
response.Headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = new TimeSpan(31536000 * TimeSpan.TicksPerSecond)
};
response.Headers.ETag = new EntityTagHeaderValue($"\"{responseHash}\"");
return true;
}