[wp-hackers] WP_Object_Cache problem

Brad Williams bradw at illiams.com
Fri Dec 11 16:42:42 UTC 2009

I'm looking for some help in understanding the WP_Object_Cache class.  I've
read through the Codex article here:



And also Doug Campbell's blog post here:



But I'm having problems getting it to work across page loads.  Below is my
basic example script:


add_action('admin_init', 'gmp_cache');


function gmp_cache() {


                $mydata = wp_cache_get('gmp-plugin', 'complex-query');


                if (false === $mydata) {

                                echo "CACHE does not exist";


                                $mydata = "my cached data";

                                $myexpire = 60 * 60 * 24; // Cache data for
one day (86400 seconds)

                                wp_cache_set('gmp-plugin', $mydata,
'complex-query', $myexpire);


                                echo "CACHE DOES EXIST";

                                $mydata = wp_cache_get('gmp-plugin',

                                echo $mydata;




Basically this will always display "CACHE does not exist.  However if I
display the cache directly after setting it the cached value does display.


I've added  define('WP_CACHE', true); to my wp-config.php file and created
the directory wp-content/cache that is writable by the server.  


Am I missing something obvious here?  There isn't a lot of recent
information on the caching class




-Brad Williams



More information about the wp-hackers mailing list