Varnish makes your websites go faster. Memcached, makes your websites go faster. Blog posts abound on using Varnish’s excellent embedded C functionality to link libmemcached into your VCLs, and Poul himself has written about his surprise in learning that many VCLs were actually thin wrappers around a C library where all of the business logic of a VCL would live.
Starting in Varnish 3, the balance can now shift back towards the VCL itself as the driver of business logic, with first-class “vmod” modules providing new VCL functions. (If you’ve been around a while, you might recognize the same progression that PHP took in the late 90’s and early 2000’s, back when PHP looked like a promising future.)
Without further ado, I present libvmod-memcached, a Varnish Memcached Module. Here’s a quick example script that flushed the cache for a page every 20 hits.
Note that VCL does not allow arbitrary variables, so I’m doing two memcached queries here. Fixing that will be another blog post!