Varnish Default TTL

by , , revisited on

We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install NGINX, Varnish and lots of useful modules for them, this is your one stop repository to get all performance related software.
You have to maintain an active subscription in order to be able to use the repository!

Varnish default TTL is the time for which an object is cached, when no cache information has been sent by your application. The default is 120 seconds (2 minutes).

When doest Varnish default TTL apply?

Most of the modern PHP apps do not send any cache related headers (Cache-Control), thus the default 120 seconds applies if you installed Varnish and haven’t configured much.

Deciding on correct default TTL value

Common approach to the matter of deciding on the correct value depends on your application. But for the most part, the correct strategy is setting the default TTL to a really high value: raise it to 2 weeks; and make your application send PURGE request to Varnish when there’s need to invalidate an object in cache.

Change Varnish default TTL via VCL

This is the most straightforward approach. Adjust your VCL to include:

sub vcl_backend_response {
    set beresp.ttl = 2w;

Change default TTL in Varnish configuration

This is preferred way to change it. However, not only it depends on the operating system in use but also where Varnish package came from.

CentOS 7. Varnish installed from EPEL repository

Open /etc/varnish/varnish.params and adjust the value (specified in seconds) to 2 weeks:


CentOS 7. Varnish installed from its official repository

Open /etc/varnish/varnish.params and add default TTL as parameter in DAEMON_OPTS like so:

DAEMON_OPTS="-t 1209600 ... other parameters ..."

Verify change to default TTL

The following command will show the default TTL that applies to currently launched Varnish instance:

varnishadm default_ttl

Naturally, the command will show the correct value if you changed TTL via configuration and not the VCL approach.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.