May 23, 2011
1 min read time

Varnish 3.0 - the Standard Module

Module support is perhaps the most exciting feature of Varnish Cache 3.0. It makes it really easy to add quite complex business logic in Varnish or to connect Varnish to any external data source. Do you want to connect Varnish to your MySQL database, so that it will authorize users against a table in MySQL? It's now easy and simple to write a module that does that. It will probably wreck havoc on performance but that's your decision - not ours.

Varnish will, at least initially, ship with one module. The standard module. As true Unix devotees we're really skimpy on the vocals so we've named it the std module. A short overview of what it does:

  • case conversion - std.toupper and std.tolower will uppercase or lowercase strings.
  • set_up_tos - It sets the TOS-flag for the current session. Say you have a download section on your website and you want to the low priority flag on these downloads. You can now do so. Pretty cool.
  • Generating random floating numbers. std.random
  • Logging to the shared memory segment or to syslog
  • Read files from the filesystem. With this you can turn Varnish into a really crappy webserver. :-)
  • ... and a few more. See the reference docs for more.

I expect the module to grow a bit as time goes by. There are lots of basic functionality like string and number handling that could be nice to have. Itching that scratch in Varnish has never been simpler. If your itch requires a separate module you should fork the example vmod on Github.

Got an itch or an idea for a great module? Share it in the comment section below.