Caching for get_pages

git-svn-id: https://develop.svn.wordpress.org/trunk@4521 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2006-11-23 17:21:08 +00:00
parent 350c99b608
commit 5b2ba1257f
1 changed files with 17 additions and 4 deletions

View File

@ -1038,6 +1038,11 @@ function &get_pages($args = '') {
$r = array_merge($defaults, $r); $r = array_merge($defaults, $r);
extract($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 = ''; $inclusions = '';
if ( !empty($include) ) { if ( !empty($include) ) {
$child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include
@ -1117,9 +1122,17 @@ function &get_pages($args = '') {
if ( $child_of || $hierarchical ) if ( $child_of || $hierarchical )
$pages = & get_page_children($child_of, $pages); $pages = & get_page_children($child_of, $pages);
$cache[ $key ] = $pages;
wp_cache_set( 'get_pages', $cache, 'page' );
return $pages; 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() { function generate_page_uri_index() {
global $wpdb; global $wpdb;