[wp-hackers] WP_Object_Cache and integration with bbPress

Michael D Adams mikea at turbonet.com
Fri Jan 4 07:27:58 GMT 2008


I'm looking to integrate WordPress' object cache with bbPress'.  With  
an common object cache mechanism, sites that load bbPress and  
WordPress on the same page view would gain a bit in efficiency, any  
persistent cache would be kept smaller, developers would only have to  
learn/write one kind of cache system, and site owners would be able to  
use the same object cache plugins (e.g. the memcache or APC plugins)  
for bbPress, WordPress, or both.

So, if you have a site with a WordPress install and a bbPress install  
both talking to the same memcached server (for example), we have to  
make sure bbPress doesn't poison WordPress' data or vice versa.   
That's easy, though.  We just have WordPress and bbPress store data in  
different cache groups:

WordPress posts: wp_cache_get( $post_id, 'posts' );
bbPress posts:   wp_cache_get( $bb_post_id, 'bb_posts' );


What about users though?

Some sites (I think most sites) will have a unified user base for  
their WordPress and bbPress installs.  Let's take WordPress.com as an  
example.  There, WordPress mu and bbPress share the same users table.   
Since it's the same data, it'd be silly to cache it all twice like the  
following would do:

WordPress user: wp_cache_get( $user_id, 'users' );
bbPress user:   wp_cache_get( $user_id, 'bb_users' );

So for the specific case of user data, it makes since to store them in  
the same place:

WordPress user: wp_cache_get( $user_id, 'users' );
bbPress user:   wp_cache_get( $user_id, 'users' );


But other sites (I think only a few sites) will *not* have a unified  
user base for their WordPress and bbPress installs.  Let's take  
WordPress.org as an example.  There, WordPress and bbPress do not  
share the same user table.  Since it's different data, we have to  
store it in different places.


So.  My suggestion is for WordPress and bbPress to use different cache  
groups for their respective users.

WordPress user: wp_cache_get( $user_id, 'users' );
bbPress user:   wp_cache_get( $user_id, 'bb_users' );

But to have the cache mechanism consider those two groups as  
synonymous;  wp_cache_get() would be written to look in the same place  
(and therefore return the same result) in either of the above cases.   
(Actually, wp_cache_get() wouldn't have a clue.   
WP_Object_Cache::get() would do the work.)

So we'd have something like:

class WP_Object_Cache {
	var $group_translations = array( 'bb_users' => 'users' );

	function get( $key, $group ) {
		if ( isset($this->group_translations[$group]) )
			$group = this->group_translations[$group];

		...
	}
}

By default, then, the object cache would assume that WordPress' and  
bbPress' user bases were unified.  If that weren't true for your  
particular set up, you'd write some small plugin that would modify the  
translation table (or write a complete new object cache, I suppose).

Or core WordPress could have an empty translation table (but  
WP_Object_Cache::get() would still know what to do with a translation  
table), and bbPress would add the necessary bits.

Another option would be to just store user data twice and not care  
about any supposed efficiency loss.

Thoughts?

--mdawaffe


More information about the wp-hackers mailing list