Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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 Jun 20 '11 at 3:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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