In vcl_recv
I decide whether to pass or lookup based on the existence of a cookie:
sub vcl_recv {
if (req.http.Cookie ~ "(JSESSIONID=)" ) {
/* do not cache logged in users */
return (pass);
}
return (lookup);
}
In vcl_fetch
I fine tune caching for some pages:
sub vcl_fetch {
/* custom rules block */
if (req.url ~ "^/foo") { set beresp.ttl=30s; }
if (req.url ~ "^/bar") { set beresp.ttl=1m; }
if (req.url ~ "^/123") { set beresp.ttl=10m; }
return (deliver);
}
How can I know within vcl_fetch
whether I am in pass or lookup mode? I'd like to be able to avoid running the "custom rules block" if I am in lookup mode because the logged in users will anyway run in pass mode so these rules do not apply to them.
You can always set a custom header in vcl_recv:
But I think it will be much cleaner to put your login on
vcl_pass
[1] or just perform your original check on vcl_fetch:[1] https://www.varnish-software.com/static/book/VCL_functions.html#vcl-vcl-pass