[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:
http://codex.wordpress.org/Function_Reference/WP_Cache
And also Doug Campbell's blog post here:
http://dougal.gunters.org/blog/2006/07/21/using-the-wordpress-object-cache
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);
}Else{
echo "CACHE DOES EXIST";
$mydata = wp_cache_get('gmp-plugin',
'complex-query');
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
Thanks!
-Brad Williams
@williamsba
More information about the wp-hackers
mailing list