public IActionResult Get() { var responseHeaders = Response.GetTypedHeaders(); responseHeaders.CacheControl = new CacheControlHeaderValue { SharedMaxAge = TimeSpan.FromSeconds(120) }; responseHeaders.LastModified = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromMinutes(10)); var etag = new ETag("backend2", isWeak: false); responseHeaders.ETag = etag.ToETagHeaderValue(); var conditionalDirective = Request.ReadConditionalReqeustDirective(); var status = conditionalDirective.ShouldPerformRequest(CurrentRepresentation.Existing(responseHeaders.LastModified.Value, etag)) ? StatusCodes.Status200OK : StatusCodes.Status304NotModified; return BuildBackendResult(status); }
public IActionResult Get() { var conditionalDirective = Request.ReadConditionalReqeustDirective(); var responseHeaders = Response.GetTypedHeaders(); var maxAge = TimeSpan.FromMinutes(10); responseHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, MaxAge = maxAge, SharedMaxAge = TimeSpan.FromMinutes(3), }; var lastModified = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromMinutes(30)); var etag = new ETag("backend1", isWeak: false); responseHeaders.ETag = etag.ToETagHeaderValue(); responseHeaders.LastModified = lastModified; responseHeaders.Expires = DateTimeOffset.UtcNow + maxAge; Response.Headers[HeaderNames.Age] = 30.ToString(); var status = conditionalDirective.ShouldPerformRequest(CurrentRepresentation.Existing(lastModified, etag)) ? StatusCodes.Status200OK : StatusCodes.Status304NotModified; return BuildBackendResult(status); }