Setting costum ttl in two-tier varnish set-up

Eivind Bengtsson ebe at dmi.dk
Thu Apr 15 12:34:03 CEST 2010


Hi list,

We are testing a set-up, where our varnish first asks its neighbour and then 
if the neighbour also does not have the object, fetch it at the "real" backend.

We do not use the expirery headers in the backend response, but set a ttl, 
depending on the page requested.
Therefore we wish the second level varnish to set a ttl maching the remainder 
of ttl in the first varnish.

so in vcl_deliver we do

sub vcl_deliver {
         if(client.ip ~ varnish_acl && resp.status == 200) {
                 unset resp.http.Via;
                 unset resp.http.X-Varnish;
                 set resp.http.varnish-age = resp.http.Age;
		}
}

and in vcl_fetch:

sub vcl_fetch {
	...
	...
         if ( req.url ~ "^/dmi/index/danmark/varsler/" ) {
                 set obj.ttl = 60s;
         } #1 min
         if ( req.url ~ "^/dmi/radaranim2.gif") {
                 set obj.ttl = 300s;
	} #5 min
	...
	...
	if (req.backend == varnish_neighbour && obj.status == 200) {
                 C{
                 VRT_l_obj_ttl(sp, (VRT_r_obj_ttl(sp) - atoi(VRT_GetHdr(sp, 
HDR_OBJ, "\014Varnish-Age:") ) ) );
                 }C
         }
}

Is this a viable way to set the ttl? Which special cases can you guys think 
of, in which the proposed c-code doesnt work as expected?
e.g. what happens if obj_ttl is negative ?

Regards

-- 
Eivind Bengtsson
Systemadministrator - Cand.merc.(dat)
Danmarks Meteorologiske Institut
Lyngbyvej 100
2100 København Ø
Direkte tlf. : 39157544
Email: ebe at dmi.dk
echo 'This is not a pipe.' | cat -> /dev/tty




More information about the varnish-misc mailing list