1

I have a function to instantiate a class to provide var access to other functions.

function my_data(){
global $post,$the_data;
$postid = get_the_ID();
$the_data = new MY_Class ( $postid );
return $the_data;
}

This function will be called by every post, and each post will call it many times whenever need a var from MY_Class. The data is saved in WordPress postmeta and retrived in My_Class. Does WP automatically cache the object, or should I find a way to cache it? How?

1 Answer 1

1

If you use the WordPress API to retrieve the metadata, then it should be cached for you.

If you do other complex stuff, there is the Transients API for caching data yourself, which will take advantage of whatever object cache you use with WordPress.

EDIT - I should clarify, it'll be loaded for each request unless you use some sort of caching plugin, though it should load only once for each request.

1
  • Thanks, Milo! I use get_post_custom to retrive the data from postmeta table. So, that means the objects are cached. That's great!
    – Jenny
    Commented Jun 20, 2011 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.