Easiest Way to Temprarily Disable Varnish Cache (varnishadm)

What is the easiest way to tell varnish:

Hey Varnish processes, please clear your cache. And also please don't cache anything at all right now. I want you to just pass all requests straight to the backend for now. I'll let you know when I want you to go back to normal operation in a bit.

I'm doing some debugging and iterating on a website, but I'm tired of constantly clearing my cache with this command between every change & new request.

varnishadm 'ban req.url ~ "."'

Also, this is a fairly complex varnish config that has many backends for many distinct websites & domains.

I just want the simplest command that will tell varnish to temporarily force all requests to the backend.

# this command does not exist
varnishadm 'caching-pause req.url ~ "."'

And the corresponding simple command to restore varnish back to normal operation.

# this command also does not exist
varnishadm 'caching-resume req.url ~ "."'

Is there some easy way to tell varnish to temporarily stop caching everything?


Solution 1:

Ensure the following VCL code is in /etc/varnish/no-cache.vcl:

vcl 4.0;

backend default {
    .host = "your-host";
    .port = "your-port";
}

sub vcl_recv {
    return(pass);
}

Then load the VCL as follows:

varnishadm vcl.load nocache /etc/varnish/no-cache.vcl

Whenever you want Varnish to bypass the cache, run the following command:

varnishadm vcl.use nocache

If you want to go back to normal operations and your regular VCL is named boot, just use the following command:

varnishadm vcl.use boot

You can use varnishadm vcl.list to see the list of loaded VCL files and to see which one is active.