From 226a7a48eb5da03ebd90c85e6694e8d0337cd3b1 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 23 Nov 2006 17:21:08 +0000 Subject: [PATCH] Caching for get_pages git-svn-id: http://svn.automattic.com/wordpress/trunk@4521 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 7192f4d805..04b5291aa4 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1038,10 +1038,15 @@ function &get_pages($args = '') { $r = array_merge($defaults, $r); extract($r); + $key = md5( serialize( $r ) ); + if ( $cache = wp_cache_get( 'get_pages', 'page' ) ) + if ( isset( $cache[ $key ] ) ) + return apply_filters('get_pages', $cache[ $key ], $r ); + $inclusions = ''; if ( !empty($include) ) { - $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include - $exclude = ''; + $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include + $exclude = ''; $meta_key = ''; $meta_value = ''; $incpages = preg_split('/[\s,]+/',$include); @@ -1054,8 +1059,8 @@ function &get_pages($args = '') { } } } - if (!empty($inclusions)) - $inclusions .= ')'; + if (!empty($inclusions)) + $inclusions .= ')'; $exclusions = ''; if ( !empty($exclude) ) { @@ -1117,9 +1122,17 @@ function &get_pages($args = '') { if ( $child_of || $hierarchical ) $pages = & get_page_children($child_of, $pages); + $cache[ $key ] = $pages; + wp_cache_set( 'get_pages', $cache, 'page' ); + return $pages; } +function delete_get_pages_cache() { + wp_cache_delete( 'get_pages', 'page' ); +} +add_action( 'save_post', 'delete_get_pages_cache' ); + function generate_page_uri_index() { global $wpdb;