Caching for get_categories
git-svn-id: https://develop.svn.wordpress.org/trunk@4519 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fe87cdac0b
commit
f5a9979852
@ -30,6 +30,11 @@ function &get_categories($args = '') {
|
|||||||
$r['number'] = (int) $r['number'];
|
$r['number'] = (int) $r['number'];
|
||||||
extract($r);
|
extract($r);
|
||||||
|
|
||||||
|
$key = md5( serialize( $r ) );
|
||||||
|
if ( $cache = wp_cache_get( 'get_categories', 'category' ) )
|
||||||
|
if ( isset( $cache[ $key ] ) )
|
||||||
|
return $cache[ $key ];
|
||||||
|
|
||||||
$where = 'cat_ID > 0';
|
$where = 'cat_ID > 0';
|
||||||
$inclusions = '';
|
$inclusions = '';
|
||||||
if ( !empty($include) ) {
|
if ( !empty($include) ) {
|
||||||
@ -119,9 +124,20 @@ function &get_categories($args = '') {
|
|||||||
}
|
}
|
||||||
reset ( $categories );
|
reset ( $categories );
|
||||||
|
|
||||||
|
$cache[ $key ] = $categories;
|
||||||
|
wp_cache_set( 'get_categories', $cache, 'category' );
|
||||||
|
|
||||||
return apply_filters('get_categories', $categories, $r);
|
return apply_filters('get_categories', $categories, $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete_get_categories_cache() {
|
||||||
|
wp_cache_delete('get_categories', 'category');
|
||||||
|
}
|
||||||
|
add_action( 'wp_insert_post', 'delete_get_categories_cache' );
|
||||||
|
add_action( 'edit_category', 'delete_get_categories_cache' );
|
||||||
|
add_action( 'add_category', 'delete_get_categories_cache' );
|
||||||
|
add_action( 'delete_category', 'delete_get_categories_cache' );
|
||||||
|
|
||||||
// Retrieves category data given a category ID or category object.
|
// Retrieves category data given a category ID or category object.
|
||||||
// Handles category caching.
|
// Handles category caching.
|
||||||
function &get_category(&$category, $output = OBJECT) {
|
function &get_category(&$category, $output = OBJECT) {
|
||||||
|
Loading…
Reference in New Issue
Block a user