From e05b055337f73226d03b6d9b5cc1208bbf1e5acb Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 23 Nov 2006 16:52:42 +0000 Subject: [PATCH] Caching for get_categories git-svn-id: http://svn.automattic.com/wordpress/trunk@4519 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wp-includes/category.php b/wp-includes/category.php index 76382ad095..7b3e7cae33 100644 --- a/wp-includes/category.php +++ b/wp-includes/category.php @@ -30,6 +30,11 @@ function &get_categories($args = '') { $r['number'] = (int) $r['number']; 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'; $inclusions = ''; if ( !empty($include) ) { @@ -119,9 +124,20 @@ function &get_categories($args = '') { } reset ( $categories ); + $cache[ $key ] = $categories; + wp_cache_set( 'get_categories', $cache, 'category' ); + 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. // Handles category caching. function &get_category(&$category, $output = OBJECT) {