How to make Varnish not caching response if they do not have proper cache header?

Jonathan Matthews contact at
Sun Mar 25 12:10:19 CEST 2012

On 25 March 2012 05:15, Ryan Chan <ryanchan404 at> wrote:
> Seems Varnish is caching too aggressively, e.g. I have a index.php does not
> send out last-modifieid,cache-control, Varnish still cache it.
> my default.vcl
> backend default {
>     .host = "";
>     .port = "8080";
> }
> Is it possible to turn off this strange behaviors?

Your responses are probably being cached because of the default
default_ttl setting, which you'll find detailed a little way down

However, rather than changing that run-time setting, you may want to
force Varnish always to contact the back-end next time for those
resources which don't dictate an explicit TTL. This would be both more
visible and more tunable, later on.

This VCL would achieve that goal, I believe (untested, but taken from the docs):

sub vcl_fetch {
  if (beresp.ttl <= 0s) {
    # Mark as "Hit-For-Pass" for the next 2 minutes
    set beresp.ttl = 120s;
    return (hit_for_pass);

Jonathan Matthews
London, Oxford, UK

More information about the varnish-misc mailing list