Just committed a version with WP Super Cache support. I’m going to test this out a bit more on my own site with a couple public experiments, but it seems to all be working well in the lab.

Here is how the WP Super Cache support works: when you access a page, we see (a) what experiments are running on that page and (b) for each of those experiments, which variant you are assigned to. This is encoded in a string which is added to the wp_cache_key. In the simplest case, let’s say your page has one experiment on it with two variants. Some users will end up with a cache key for variant A, which may be cached, and some users will end up with a different cache key for variant B. In this way, you can take advantage of caching even on pages which are running live experiments. If a page records a metric on it, caching is disabled on that page. (As we need to access the database in order to see which variant the visitor is assigned to, this unfortunately requires WP Super Cache’s “half on” mode.)

Getting this to work was slightly difficult and involved putting in some additional infrastructure to track what experiments affect which pages. So far I had simply been tracking that (using the touch_* functions) throughout execution so that by the end of the request, we have a list of which experiments and metrics were “touched” on that page. However, waiting for the entire page to render is of course too late to determine the cache status at the beginning of the request. I thus now built a caching-type system in a new table, request_touches, which records what experiments and which metrics are touched, given a request URL.

This WP Super Cache support now means that experiments can run “live” on a page, with different treatments (or even different combinations of treatments for different experiments!) served via Super Cache with “almost as good as static” performance. Best case, only one database call is made before routing the visitor to the appropriate cached copy.

Unfortunately, though, you have to move the WP Super Cache plugin (called shrimptest-supercache.php) into plugins/wp-super-cache/plugins, but that’s just how we need to interface WP Super Cache. That is, if we can’t get Donncha to bundle the ShrimpTest WP Super Cache plugin with WP Super Cache itself. 😉

Thanks to Donncha for giving me some tips on writing a WP Super Cache plugin! The documentation is here.