SV: VCL language

Anders Berg Anders.Berg at vg.no
Thu Mar 30 14:02:49 CEST 2006


 

> In message 
> <1543.193.213.34.102.1143676134.squirrel at denise.vg.no>, 
> "Anders Berg" writes:
>
> I think a large part of the solution is to come up with some 
> clear examples to show people how to do things.
> 
> Is this an improvement ?
>
> 1     backend default {
> 2         set backend.ip = 10.0.0.1;
> 3     }
> 4
> 5     proc main {
> 6	  if (req.request != "GET" && req.request != "HEAD") {
> 7	      pass_through;
> 8	  }
> 9	  lookup_object;
> 10	  if (obj.valid) {
> 11            finish;
> 12	  }
> 13	  fetch;
> 14        if (obj.url ~ "[.]hbs$") {
> 15            obj.ttl = 5m;
> 16            obj.cacheable = true;
> 17        } elif (obj.url ~ "[.]jpg$" || obj.url ~ "[.]gif$") {
> 18            obj.ttl = 1w;
> 19            obj.cacheable = true;
> 20        } elif (obj.url ~ "/poor_written") {
> 21            obj.ttl = 5m;
> 22            obj.cacheable = true;
> 23        }
> 24	  if (obj.cacheable) {
> 25	      insert;
> 26	  }
> 27    }

Yes, this is better, but I like the one underneath even better.

> 14,17,20:  a '.' in a regexp means "any character", putting it in [.]
> 	   is a readable way to escape it.  Because we use strings
> 	   enclosed in double-quotes, the backslash-escape would be
> 	   "\\.jpg$".  The trailing '$' is to avoid false matches.
> 
> 	   Of course, we could also add a 
> 		if (obj.suffix = ".hbs")
> 	   if we wanted to make this easier/faster.
> 
> 15,16:	   We could let the "obj.cacheable = true" be 
> implicit when
> 	   obj.ttl is set, I can't really see why we shouldn't ?
> 
> 17:        Another way to write it could be:
> 
> 	   if (obj.content_type ~ "image/") {
> 
> So with those changes it would look like this:
> 
> 1     backend default {
> 2         set backend.ip = 10.0.0.1;
> 3     }
> 4
> 5     proc main {
> 6	  if (req.request != "GET" && req.request != "HEAD") {
> 7	      pass_through;
> 8	  }
> 9	  lookup_object;
> 10	  if (obj.valid) {
> 11            finish;
> 12	  }
> 13	  fetch;
> 14        if (obj.suffix = ".hbs") {
> 15            obj.ttl = 5m;
> 16        } if (obj.content_type ~ "image/") {
> 17            obj.ttl = 1w;
> 18        } elif (obj.url ~ "/poor_written") {
> 19            obj.ttl = 5m;
> 20        }
> 21	  if (obj.cacheable) {
> 22	      insert;
> 23	  }
> 24    }

This looks good, apart from 1 thing.

21 if (obj.cacheable) {
22	      insert;
23	  }

I guess most appications have a Expires header either they are right or
not. So while obj.cacheable is good and we should keep it, we need maybe
1 more.
So I would suggest a 

21 if (obj.url ~ "/nicely_written"){
22    trust_header;
23 }

This is the same as:

21 if (obj.url ~ "/nicely_written"){
22   if (obj.cacheable) {
23	      insert;
24	  }
25  }

I think this is a good abstraction.

Good work. This problem could maybe just be a semantic and
implementation challange.

Anders Berg

> 
> -- 
> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
> phk at FreeBSD.ORG         | TCP/IP since RFC 956
> FreeBSD committer       | BSD since 4.3-tahoe    
> Never attribute to malice what can adequately be explained by 
> incompetence.
> _______________________________________________
> varnish-dev mailing list
> varnish-dev at projects.linpro.no
> http://projects.linpro.no/mailman/listinfo/varnish-dev
> 


*****************************************************************
Denne fotnoten bekrefter at denne e-postmeldingen ble
skannet av MailSweeper og funnet fri for virus.
*****************************************************************
This footnote confirms that this email message has been swept by
MailSweeper for the presence of computer viruses.
*****************************************************************




More information about the varnish-dev mailing list