[wp-hackers] Difference in behaviour between WP_Object_Cache and W3_ObjectCache

Gabriel Koen gabriel.koen at gmail.com
Thu Mar 10 00:43:00 UTC 2011

Hi all,

I'm seeing different behaviour in interacting with objects cached using WordPress's built-in object cache and W3 Total Cache.  There's something here I'm missing.  

// Add a post to the object cache
$post_id = 123;
$post_object = new stdClass();
$post_object->ID = $post_id;
$post_object->post_title = 'Original title';
wp_cache_set($post_id, $post_object, 'posts');

// Retrieve the post from the object cache
$post = wp_cache_get($post_id, 'posts');

// Change the post title
$post->post_title = 'Hello, world';

// Get a new copy of the post from the object cache
$post_cache = wp_cache_get($post->ID, 'posts');

// Compare the object fresh from cache with the locally-modified object
echo $post->post_title . "\n";
echo $post_cache->post_title . "\n";

Output when using WordPress's built-in object cache:
Hello, world
Original title

Output when using W3TC's object cache dropin, with object caching disabled:
Hello, world
Hello, world

I just don't see what could be causing the difference in behaviour when looking at the cache set and cache get methods.

Gabriel Koen
gabriel.koen at gmail.com

More information about the wp-hackers mailing list