post_cache

Just like category_cache, WordPress uses post_cache global variable to cache all the posts by their IDs. It is set in the function update_post_caches($posts) defined in [wordpress root folder]/wp-includes/functions.php. post_cache is an array and indexes post by the post ID. WordPress provides function clean_post_cache($id) to cleanup or unset the post for the specified ID.

post_cache is internally used by WordPress in following functions:

  • get_posts($args): codex document
  • get_children($post = 0, $output = OBJECT): returns child posts of the specified post. If not post is specified, children of current post are returned. This is specifically useful when retrieving heirarchical static pages.

Plugin and theme developers can use the cache when retrieving the entire posts or individual fields. They can also use update_post_caches($posts) to update the cache. This function also updates the category cache using update_post_category_cache($post_ids).

Technorati tags: , , .

One Response to “post_cache”


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: