24

I have discovered that I can set the TTL in Varnish as follows in my VCL file:

sub vcl_fetch {
    # 1 minute
    set obj.ttl = 1m;
}

But what is the default setting (assuming the backend server is setting no cache-control header) ?

1
  • Looks like I've found the answer: 120 seconds - this is in the default VCL logic.
    – Ade
    May 15, 2012 at 11:42

2 Answers 2

24

This is in the default template:

sub vcl_fetch {
    if (beresp.ttl <= 0s ||
        beresp.http.Set-Cookie ||
        beresp.http.Vary == "*") {
                /*
                 * Mark as "Hit-For-Pass" for the next 2 minutes
                 */
                set beresp.ttl = 120 s;
                return (hit_for_pass);
    }
    return (deliver);
}

So, 120 seconds.

5
34

Default TTL can be passed through the varnishd command via the -t commandline switch and is probably sourced from a properties file on your filesystem. On the CentOS system I'm looking at it is set using DEFAULT_TTL from /etc/sysconfig/varnish.

You can see the live setting using varnishadm like so,

varnishadm param.show default_ttl

Actually, following default VCL logic relates to non-cacheable objects.

  sub vcl_fetch {
      if (beresp.ttl <= 0s ||
          beresp.http.Set-Cookie ||
          beresp.http.Vary == "*") {
                  /*
                   * Mark as "Hit-For-Pass" for the next 2 minutes
                   */
                  set beresp.ttl = 120 s;
                  return (hit_for_pass);
      }
      return (deliver);
  }

means "if object is not cacheable - pass client requests for this object to backend directly and simultaneously for 2 minutes, do not queue them"

Read more at https://stackoverflow.com/questions/12691489/varnish-hit-for-pass-means

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.