I’ve been reading about Couchbase, and I knew it was compatible with Memcached out of the box. One of the features I wanted to start using was
Memcached::setMulti. I knew the Memcached WP Object Cache plugin had a
get_multi method, but I didn’t know what it did or how it did it. Turns out, it doesn’t implement
When I looked under the hood, I realized that the Memcache extension is loads different than the Memcached extension in PHP. Memcached has the
getMulti method, Memcache does not. So I set out to change this: I have altered the famed Memcached plugin to actually use the Memcached class.
Because I did this, you can now use methods like this:
wp_cache_get_multi( array( array( 'key', 'group' ), array( 'key', '' ), array( 'key', 'group' ), 'key' ) ); wp_cache_set_multi( array( array( 'key', 'data', 'group' ), array( 'key', 'data' ) ) );
Rather than making many calls to grab data, especially related data, you can grab it in one hop.
I’m gonna keep working on the plugin, and drop a line if you install it and have comments / concerns.
The Plugin: Memcached Redux
In your plugin following properties are initialized arrays:
var $global_groups = array();
var $no_mc_groups = array();
Do you need to assign a value to the properties like so?:
var $global_groups = array (‘users’, ‘userlogins’, ‘usermeta’, ‘site-options’, ‘site-lookup’, ‘blog-lookup’, ‘blog-details’, ‘rss’);
var $no_mc_groups = array( ‘comment’, ‘counts’ );
var $autoload_groups = array (‘options’);
Is this plugin working for you without leakage or data loss? Are you testing it on a production server?
I rolled a change a few weeks ago – memcached on Linux was returning -1 instead of NULL for empty / non-existent values, I was only checking for === NULL. Maybe that was it? Try it again.
Pingback: Working With Memcached in WordPress | 10up
Gave a try. It makes the blog inaccessible. Doesn’t work at all.
I currently use http://wordpress.org/extend/plugins/memcached/ version 2.0.1 which leaks and loses a lot of data, and only runs about 84% efficiency, as opposed to 2.0 which ran at about 95% efficiency or better. I can’t use 2.0 any longer because I now have a mixed environment of single site and multisite installations.
Box is CentOS 6.2 running the latest Memcached from YUM repository.
Are you using your plugin?
yeah, in prod at eMusic – I think you may need to clear your Memcached completely and restart the instances
Gave restart a try. Same result. I only dropped-in the plugin on one of the single site blogs. It shouldn’t matter if I use a different memcached plugin for the other blogs.
nothing in your apache logs?
I run Nginx with PHP-FPM, and no, nothing in the logs.
unfortunately, I haven’t tested it with nginx yet – all I can say, I had problems for about 15 minutes when I rolled the new code, but everything was kosher after I flush_all’d each server from telnet.
Not sure what the problem is.
I will take a look at it again later. Thank you for working on adding multi functions.
Who did the banner for your plugin page http://wordpress.org/extend/plugins/memcached-redux/?
I get all of them by scouring Google Images, no clue of the origin
I just figured out the problem. Your plugin requires the memcached extension, which is the reason you can use the PHP multi functions:
The Memcached 2.0.1 plugin requires the old memcache extension, which has no PHP multi functions:
I would have to switch everything over to the new extension to try your plugin, which I will one late night to see how well it does.
The plugin and the blog post say exactly that 🙂
Yup. I need to read slower.
Just wanted to correct this statement from above when I said:
“I currently use http://wordpress.org/extend/plugins/memcached/ version 2.0.1 which leaks and loses a lot of data, and only runs about 84% efficiency, as opposed to 2.0 which ran at about 95% efficiency or better.”
I discovered the problem was WordPress SEO plugin written by Yoast. It was executing the wp_cache_flush, and wp_cache_delete functions with extreme frequency. After commenting out the two lines with those functions all my problems went away, and now the GET hits are back to 95% or better.
Didn’t want anyone getting a wrong impression about the Memcached Object Cache 2.0.1 plugin.
Are you sure the Memcache module doesn’t support multi-gets? The get function accepts an array of keys and will return an array of values. I’m not sure how this is implemented under the hood, but it may get multiple keys at once.