WordPress object cache with memcached backend for vanilla WordPress

WordPress object cache with memcached backend is mainly meant for WPMU and doesn’t work well if you happened to have many vanilla WordPress installations using the same memcached backend like it is pointed out here and here.

I have created a simple patch which you can apply against object-cache.php (downloadable from WordPress plugin repository) or here is the file already patched. The patch prepends the $blog_id to the object key. You will have to specify global variable $blog_id in wp-config.php and give it a unique id (like your blog url).
[sourcecode language=’php’]global $blog_id;
$blog_id = ‘mohanjith_net’;[/sourcecode]

Using memcached with WordPress object cache

I like the web pages to be snappy, including my blog. I found my blog to be bit slow after I moved to WordPress even after performance tuning. After looking around for a solution I came across memcache back-end for WordPress object cache which can be downloaded from here. You have to drop the file object-cache.php into wp-content/. You will have to specify the memcached servers by adding the following lines to wp-config.php.
[sourcecode language=’php’]global $memcached_servers;
$memcached_servers = array(‘default’ => array(‘127.0.0.1:11211’));[/sourcecode]
My blog loaded faster than before, it was all good. Afterwards I wanted to install the memcache back-end for WP object cache on my mother’s blog using the same memcached server. I just dropped the wp-config.php file into my mother’s installation of WordPress. That’s when things became awry. My mother’s blog started to redirect to my blog 🙁 . After looking at wp-config.php closely it was clear to me it was designed for WordPress MU. However I didn’t want to give up on using memcache with WordPress. Looking even closer I noticed that I can specify the global variable $blog_id and it would be perpended to the memcache object key. I added the following line to wp-config.php in my mother’s WordPress installation in addition to the two lines above and applied this patch (patched object-cache.php).
[sourcecode language=’php’]global $blog_id;
$blog_id = ‘priyani_mohanjith_net’;[/sourcecode]
That’s it, both my blog and my mother’s blog became fast and it was working without any issues. Hope this helps someone who wants to use the same memcached server with multiple installtions of vanilla WordPress. You cannot use this technique or memcache unless your blog is self hosted on a server where you have full control.