Mike Gifford
Mike Gifford

Reputation: 661

What is the difference between beresp.grace & obj.grace

In setting up my default.vcl file (Varnish 3) I'm seeing different recommendations for vcl_fetch to use either beresp.grace or obj.grace. What is the difference?

https://www.varnish-cache.org/docs/3.0/reference/vcl.html obj.grace The object's grace period in seconds. obj.grace is writable. beresp.grace Set to a period to enable grace.

Sounds pretty much the same.

Should they be used together like https://www.varnish-software.com/static/book/Saving_a_request.html set beresp.ttl=1m; set req.grace = 30s; set beresp.grace = 1h;

I'd like some clarity. Also ideas on ttl would be useful too. Sadly many of the docs are still for V2: http://drupal.org/node/1823970

Upvotes: 3

Views: 3398

Answers (1)

Richard Hulse
Richard Hulse

Reputation: 10493

The two are used in different place in the VCL code.

Using some typical examples of (V3) use, the difference is this. (Substitute obj for req).

sub vcl_fetch {
   set beresp.grace = 1h;
}

This code is telling varnish to mark cache objects as being available for use for up to 1 hour.

Whereas this code:

sub vcl_recv {
  if (req.backend.healthy) {
    set req.grace = 30s;
  } else {
    set req.grace = 1h;
  }
}

...is telling varnish to use the marked objects for up to the time specified, based on (in this case) the backend is healthy.

TTL is how long the item is cached for, and unless you have some very particular (or odd) requirements you are best to set caching headers in your application or webserver layer).

The only time you need to set TTL in the VCL is if you want something different from what the headers are, or if you need to silently (not passing any headers to the requesting browser) extend the time objects can be cached.

Upvotes: 5

Related Questions