Automattic / babble

Multilingual WordPress done right.
https://wordpress.org/plugins/babble/
245 stars 50 forks source link

Lower memory usage in our object cache usage #236

Closed simonwheatley closed 9 years ago

simonwheatley commented 9 years ago

We generally store arrays of whole post objects in object cache, like below…

$translations = array();
foreach ( $posts as $post )
    $translations[ $this->get_post_lang_code( $post ) ] = $post;

wp_cache_add( $transid, $translations, 'bbl_post_translations' );

return $translations;

This puts a very large amount of data in memory and, if the object cache is just PHP's memory, can overwhelm PHP. Another approach might be to store the post IDs, then do a get_posts or WP_Query with suppress_filters = false and specify the specific IDs, which is another query but a very optimised one.