25

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. Commented 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
  • Where did you find the default template? Commented Oct 25, 2013 at 15:37
  • varnish-cache.org/docs/3.0/reference/vcl.html Commented Oct 25, 2013 at 19:11
  • There is a default.vcl that ships with varnish as of at least 3.0.3 which has all of the default config subroutines commented out in it. The 4.0 default config can be seen here: github.com/mattiasgeniar/varnish-4.0-configuration-templates/… Commented Aug 7, 2015 at 16:43
  • 3
    This doesn't mirror my observations. It is true that the default ttl is 120 seconds, but the source of this number can't be that snippet. If it were, objects without a ttl would be marked as hit_for_pass, but they actually remain in the cache for 120 seconds. Commented Mar 14, 2017 at 15:54
  • You'll find the source of the builtin vcl here - github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/…. Use the varnish-<version> tags to see the version for your Varnish release. Commented May 6, 2019 at 17:50
35

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.