[wp-hackers] WP-Cache vs. eAccelerator vs. Memcache vs. ... (Yeah, another server opt. discussion)

Computer Guru computerguru at neosmart.net
Sun Oct 28 09:21:55 GMT 2007


The actual engine doesn't make a difference - it'll only cache the compiled
php, and not the results from the database.

the WP plugins let WP store the results from the DB in the opcode engine. I
found it exteremely easy to hack Brian's Latest Comments to use object cache
(no more 33 extra queries per page!) to store all comments and have it
rebuild the cache when a comment is added.

WP-Cache converts everything to HTML. With object caching + my/ryan/mark's
plugin, a file "opts-in" to the caching process. Basically, you store the
results of a query/calculation in the cache, and add a hook to invalidate
that cache when needed. It's quite easy:

Original line:

$commenters = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(comment_date) AS
unixdate FROM $tablecomments
WHERE comment_approved = '1'
AND comment_post_ID = '".$post->comment_post_ID."'
$ping
ORDER BY comment_date DESC
LIMIT $num_comments;");

New line:

// BEGIN WP-CACHE CHECK
if ( ( !$commenters = wp_cache_get( 'commenters_' . $post->comment_post_ID,
'blc' ) ) || $invalidated ) {


$commenters = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(comment_date) AS
unixdate FROM $tablecomments
WHERE comment_approved = '1'
AND comment_post_ID = '".$post->comment_post_ID."'
$ping
ORDER BY comment_date DESC
LIMIT $num_comments;");


wp_cache_add( 'commenters_' . $post->comment_post_ID, $commenters, 'blc' );
}

and

add_action( 'comment_post', 'blc_clear_cache' );

So you basically check if a cache exists by a unique name. if it doesn't
store results of sql cache to the cache. add a hook to invalidate the cache
when action XXXX is performed.

Almost all of WP core uses object cache and properly invalidates it, so no
worries there. Any plugins that don't explicitly use object cache will
display dynamic data. Plugins configured to use object cache will properly
invalidate data. So no disadvantages to using it (plus, object cache code
gracefully degrades if object cache is not enabled).

You have to actively "use" the object cache, unlike wp-cache where
everything is cached. However it's really easy

On 10/28/07, Ozh <ozh at planetozh.com> wrote:
>
> How do such plugins (xcache, ea, memcache) behave regarding dynamic
> parts within files?  To say the least, WP-Cache support for dynamic
> stuff is terribly frustrating...
>
> Ozh
>
> --
> http://FrenchFragFactory.net ~ Daily Quake News
> http://planetOzh.com ~ Blog and WordPress Stuff
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Computer Guru
Director,
NeoSmart Technologies
http://neosmart.net/blog/


More information about the wp-hackers mailing list