While configuring Varnish 4, I'm interested in short-circuiting inside vcl_recv
, but I don't want to skip the builtin.vcl (née default.vcl) VCL logic. For example, given this VCL pseudocode:
sub vcl_recv {
if (somecondition1) {
set some_thing;
return (hash); # Return from cache if present, or fetch from the backend
}
if (somecondition2) {
set some_other_thing;
return (hash); # Return from cache if present, or fetch from the backend
}
// ...
return (pass); # Skip cache, fetch from the backend
}
Question 1
If I'm calling return
in every possible code path, then the built-in logic will get skipped, right?
Question 2
Is there a way to format code similar to the above, but without skipping the builtin.vcl logic? The only way I can see is to combine my conditionals, boolean !
them, and move the return (pass);
inside the giant if
.
1) Yes
2) The entire point of a return is that you skip parts of the code, that you stop it running through unneeded code (hashing, passing, missing). If you need to run it, either
a) Copy the code you need executed before the return or
b) Use a massive wrapper if.
Personally, I tend to duplicate and replace all of the built-in vcl for everything but the most basic of sites, I can get really high hitrates that way (98%+).