LOG IN SIGN UP
Documentation

Support for the Edge-Control header

VCL provides the building blocks to access information inside the Edge-Control response header field from the origin. We support this by honoring cache-maxage from Edge-Control as the time to live (TTL) of the object on the Fastly edge, and honoring downstream-ttl from Edge-Control as the TTL to be sent down from the Fastly edge to the end user's browser.

In order to incorporate this Edge-Control header support, include the following snippet in your vcl_fetch function via custom VCL:

if (parse_time_delta(subfield(beresp.http.Edge-Control, "downstream-ttl")) >= 0) {
  set beresp.http.Cache-Control = "max-age=" parse_time_delta(subfield(beresp.http.Edge-Control, "downstream-ttl"));
}

if (parse_time_delta(subfield(beresp.http.Edge-Control, "cache-maxage")) >= 0) {
  set beresp.ttl = parse_time_delta(subfield(beresp.http.Edge-Control, "cache-maxage"));
}

The subfield function parses the Edge-Control field for subfields, and the parse_time_delta function converts time values like "7m" into a number of seconds. You can then use that number of seconds to populate beresp.ttl (the TTL of the object on the Fastly edge) or you can use it to construct a Cache-Control header field for downstream. The parse_time_delta function will return -1 if the subfield is not well-formed as a time value, or if it is entirely absent. The above snippet honors cache-maxage and downstream-ttl from Edge-Control if present and usable.