[wp-hackers] Difference in behaviour between WP_Object_Cache and W3_ObjectCache
Gabriel Koen
gabriel.koen at gmail.com
Thu Mar 10 01:05:20 UTC 2011
Ah hah. I ran through the code with a colleague and found the answer. I missed it before, but WP_Object_Cache returns wp_clone($object) and W3_ObjectCache returns the original object, not a clone.
Gabriel Koen
gabriel.koen at gmail.com
On Mar 9, 2011, at 4:43 PM, Gabriel Koen wrote:
> 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.
>
> <?php
> // 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