Varnish force cache everything

varnish

Is it possible to configure Varnish 4 to cache all content regardless of what it is? I tried what's mentioned here: http://www.atomictag.com/2016/04/25/varnish-cache-all/ but my hit rate is still low.

If this is possible I can then configure Varnish to refresh the cache every 15 minutes or so from the backend. I know this is not the best practice but I am ok with serving my website visitors content that's 15 minutes old, if I can increase the website loading speed.

The Varnish server has 32 GB of RAM but only 8 GB is used. I've configured -malloc, 25G.

Best Answer

If you already tried with set beresp.ttl = 1m; as mentioned in the link you provided the reason Varnish is not caching much could be due to a number of reasons.

  1. Use varnishlog to see details of the headers and the flow of actions Varnish takes when you get a URL you are expected to be cached, for example:

sudo varnishlog -q 'ReqURL ~ "^/css/main.css" and RespHeader:Age == 0'

This will show you the details of misses for a particular URL.

  1. Find out if you are stripping the cookies properly https://www.varnish-cache.org/docs/4.1/users-guide/increasing-your-hitrate.html?highlight=cookies

  2. You can also override the Hash Varnish uses if you want Varnish to cache even similar URLs: https://varnish-cache.org/docs/trunk/users-guide/vcl-hashing.html