beresp.ttl

RTIME, can be read and set, but not unset.

Available infetch

Maximum amount of time for which the object will be considered fresh in the cache. By default, the value of beresp.ttl will be parsed from the Surrogate-Control, Cache-Control, or Expires headers received from the backend. Setting this variable takes precedence over those headers.

Conversely, setting caching headers in vcl_fetch will not affect beresp.ttl because the value of beresp.ttl is derived from the headers only once, before vcl_fetch is executed.

Once the TTL is reached, if the object has not been evicted or purged, it will become stale.

Try it out

beresp.ttl is used in the following code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.

Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Override TTLs based on content type

Set TTLs at the edge based on the type of resource. Better done at origin, but this can be a great 'quick fix' or a solution if you don't control the origin.

Serve stale content from cache while origins are offline

Deal with all potential scenarios for using stale content to satisfy requests when origin is unhealthy or misbehaving.