Index: wp-includes/category.php
===================================================================
--- wp-includes/category.php	(revision 23294)
+++ wp-includes/category.php	(working copy)
@@ -14,12 +14,8 @@
  * @return object List of all of the category IDs.
  */
 function get_all_category_ids() {
-	if ( ! $cat_ids = wp_cache_get( 'all_category_ids', 'category' ) ) {
-		$cat_ids = get_terms( 'category', array('fields' => 'ids', 'get' => 'all') );
-		wp_cache_add( 'all_category_ids', $cat_ids, 'category' );
-	}
-
-	return $cat_ids;
+	// this call returns from cache if present
+	return get_terms( 'category', array( 'fields' => 'ids', 'get' => 'all' ) );
 }
 
 /**
Index: wp-includes/taxonomy.php
===================================================================
--- wp-includes/taxonomy.php	(revision 23294)
+++ wp-includes/taxonomy.php	(working copy)
@@ -861,39 +861,41 @@
  * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param.
  *
  * @param int|object $term If integer, will get from database. If object will apply filters and return $term.
- * @param string $taxonomy Taxonomy name that $term is part of.
+ * @param string $taxonomy Optional if object is passed for $term. Taxonomy name that $term is part of.
  * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N
  * @param string $filter Optional, default is raw or no WordPress defined filter will applied.
  * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not
  * exist then WP_Error will be returned.
  */
-function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') {
+function get_term( $term, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) {
 	global $wpdb;
 	$null = null;
 
-	if ( empty($term) ) {
-		$error = new WP_Error('invalid_term', __('Empty Term'));
+	if ( empty( $term ) ) {
+		$error = new WP_Error( 'invalid_term', __( 'Empty Term' ) );
 		return $error;
 	}
 
-	if ( ! taxonomy_exists($taxonomy) ) {
-		$error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
-		return $error;
-	}
+	if ( is_object( $term ) )
+		$taxonomy = $term->taxonomy;
 
-	if ( is_object($term) && empty($term->filter) ) {
-		wp_cache_add($term->term_id, $term, $taxonomy);
+	if ( ! taxonomy_exists( $taxonomy ) )
+		return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) );
+
+	if ( is_object( $term ) && empty( $term->filter ) ) {
+		update_term_cache( $term, $taxonomy );
 		$_term = $term;
 	} else {
 		if ( is_object($term) )
 			$term = $term->term_id;
 		if ( !$term = (int) $term )
 			return $null;
-		if ( ! $_term = wp_cache_get($term, $taxonomy) ) {
+		if ( ! $_term = wp_cache_get( $term, term_cache_group( $taxonomy ) ) ) {
 			$_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) );
 			if ( ! $_term )
 				return $null;
-			wp_cache_add($term, $_term, $taxonomy);
+
+			update_term_cache( $_term, $taxonomy );
 		}
 	}
 
@@ -948,27 +950,36 @@
 		return false;
 
 	if ( 'slug' == $field ) {
+		$value = sanitize_title( $value );
+		if ( empty( $value ) )
+			return false;
+
+		$term_id = wp_cache_get( $value, term_cache_group( $taxonomy, $field ) );
 		$field = 't.slug';
-		$value = sanitize_title($value);
-		if ( empty($value) )
-			return false;
 	} else if ( 'name' == $field ) {
 		// Assume already escaped
 		$value = stripslashes($value);
+		$term_id = wp_cache_get( $value, term_cache_group( $taxonomy, $field ) );
 		$field = 't.name';
 	} else {
-		$term = get_term( (int) $value, $taxonomy, $output, $filter);
+		$term_id = $value;
+
+		return get_term( $term_id, $taxonomy );
+	}
+
+	if ( ! empty( $term_id ) ) {
+		$term = get_term( (int) $term_id, $taxonomy, $output, $filter );
 		if ( is_wp_error( $term ) )
 			$term = false;
+
 		return $term;
 	}
 
-	$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
-	if ( !$term )
+	$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value ) );
+
+	if ( ! $term )
 		return false;
 
-	wp_cache_add($term->term_id, $term, $taxonomy);
-
 	$term = apply_filters('get_term', $term, $taxonomy);
 	$term = apply_filters("get_$taxonomy", $term, $taxonomy);
 	$term = sanitize_term($term, $taxonomy, $filter);
@@ -1238,8 +1249,11 @@
 	}
 
 	// $args can be whatever, only use the args defined in defaults to compute the key
-	$filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
-	$key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key );
+	// deprecate 'list_terms_exclusions' - use 'get_terms' filter instead
+	if ( has_filter( 'list_terms_exclusions' ) )
+		_doing_it_wrong( __FUNCTION__, __( '"list_terms_exclusions" is no longer supported. Use the "get_terms" filter instead.' ), '3.6' );
+
+	$key = md5( serialize( compact( array_keys( $defaults ) ) ) . serialize( $taxonomies ) );
 	$last_changed = wp_cache_get('last_changed', 'terms');
 	if ( !$last_changed ) {
 		$last_changed = time();
@@ -2570,7 +2584,7 @@
 
 	foreach ( $object_ids as $id )
 		foreach ( $taxonomies as $taxonomy )
-			wp_cache_delete($id, "{$taxonomy}_relationships");
+			wp_cache_delete( $id, term_cache_group( $taxonomy, 'relationships' ) );
 
 	do_action('clean_object_term_cache', $object_ids, $object_type);
 }
@@ -2591,39 +2605,41 @@
 	global $wpdb;
 	static $cleaned = array();
 
-	if ( !is_array($ids) )
-		$ids = array($ids);
+	if ( ! is_array( $ids ) )
+		$ids = array( $ids );
 
 	$taxonomies = array();
+
+	$select = "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id";
+
+	$ids = array_map( 'intval', $ids );
+
 	// If no taxonomy, assume tt_ids.
-	if ( empty($taxonomy) ) {
-		$tt_ids = array_map('intval', $ids);
-		$tt_ids = implode(', ', $tt_ids);
-		$terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)");
+	if ( empty( $taxonomy ) ) {
+		$terms = $wpdb->get_results( "$select WHERE tt.term_taxonomy_id IN (" . join( ',', $ids ) . ")" );
 		$ids = array();
-		foreach ( (array) $terms as $term ) {
+		foreach ( $terms as $term ) {
 			$taxonomies[] = $term->taxonomy;
 			$ids[] = $term->term_id;
-			wp_cache_delete($term->term_id, $term->taxonomy);
 		}
 		$taxonomies = array_unique($taxonomies);
 	} else {
-		$taxonomies = array($taxonomy);
-		foreach ( $taxonomies as $taxonomy ) {
-			foreach ( $ids as $id ) {
-				wp_cache_delete($id, $taxonomy);
-			}
-		}
+		$terms = $wpdb->get_results( $wpdb->prepare( "$select WHERE tt.taxonomy = %s AND tt.term_id IN (" . join( ',', $ids ) . ")", $taxonomy ) );
+		$taxonomies = array( $taxonomy );
 	}
 
+	foreach ( $terms as $term ) {
+		wp_cache_delete( $term->term_id, term_cache_group( $term->taxonomy ) );
+		wp_cache_delete( $term->name, term_cache_group( $term->taxonomy, 'names' ) );
+		wp_cache_delete( $term->slug, term_cache_group( $term->taxonomy, 'slugs' ) );
+	}
+
 	foreach ( $taxonomies as $taxonomy ) {
 		if ( isset($cleaned[$taxonomy]) )
 			continue;
 		$cleaned[$taxonomy] = true;
 
 		if ( $clean_taxonomy ) {
-			wp_cache_delete('all_ids', $taxonomy);
-			wp_cache_delete('get', $taxonomy);
 			delete_option("{$taxonomy}_children");
 			// Regenerate {$taxonomy}_children
 			_get_term_hierarchy($taxonomy);
@@ -2649,7 +2665,7 @@
  * @return bool|array Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id.
  */
 function get_object_term_cache($id, $taxonomy) {
-	$cache = wp_cache_get($id, "{$taxonomy}_relationships");
+	$cache = wp_cache_get( $id, term_cache_group( $taxonomy, 'relationships' ) );
 	return $cache;
 }
 
@@ -2689,7 +2705,7 @@
 	$ids = array();
 	foreach ( (array) $object_ids as $id ) {
 		foreach ( $taxonomies as $taxonomy ) {
-			if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) {
+			if ( false === wp_cache_get( $id, term_cache_group( $taxonomy, 'relationships' ) ) ) {
 				$ids[] = $id;
 				break;
 			}
@@ -2717,7 +2733,7 @@
 
 	foreach ( $object_terms as $id => $value ) {
 		foreach ( $value as $taxonomy => $terms ) {
-			wp_cache_add( $id, $terms, "{$taxonomy}_relationships" );
+			wp_cache_add( $id, $terms, term_cache_group( $taxonomy, 'relationships' ) );
 		}
 	}
 }
@@ -2732,16 +2748,66 @@
  * @param array $terms List of Term objects to change
  * @param string $taxonomy Optional. Update Term to this taxonomy in cache
  */
-function update_term_cache($terms, $taxonomy = '') {
-	foreach ( (array) $terms as $term ) {
-		$term_taxonomy = $taxonomy;
-		if ( empty($term_taxonomy) )
-			$term_taxonomy = $term->taxonomy;
+function update_term_cache( $terms, $taxonomy = '' ) {
+	if ( ! is_array( $terms ) )
+		$terms = array( $terms );
 
-		wp_cache_add($term->term_id, $term, $term_taxonomy);
+	foreach ( $terms as $term ) {
+		$tax = $taxonomy;
+		if ( empty( $tax ) )
+			$tax = $term->taxonomy;
+
+		wp_cache_add( $term->term_id, $term, term_cache_group( $tax ) );
+		wp_cache_add( $term->name, $term->term_id, term_cache_group( $tax, 'names' ) );
+		wp_cache_add( $term->slug, $term->term_id, term_cache_group( $tax, 'slugs' ) );
 	}
 }
 
+/**
+ *
+ * @package WordPress
+ * @subpackage Taxonomy
+ * @since 3.6.0
+ *
+ * @param string $taxonomy Taxonomy
+ * @param string $group Optional. ids, names, slugs, or relationships.
+ */
+function term_cache_group( $taxonomy, $group = 'ids' ) {
+	$tax = get_taxonomy( $taxonomy );
+
+	if ( ! $tax )
+		return false;
+
+	if ( $tax->_builtin ) {
+		switch ( $group ) {
+			case 'names':
+			case 'slugs':
+				$key = "$taxonomy:$group";
+				break;
+			case 'relationships':
+				$key = "{$taxonomy}_relationships";
+				break;
+			default:
+				$key = $taxonomy;
+				break;
+		}
+	} else {
+		switch ( $group ) {
+			case 'ids':
+			case 'names':
+			case 'slugs':
+			case 'relationships':
+				$key = "taxonomy:$taxonomy:$group";
+				break;
+			default:
+				$key = "taxonomy:$taxonomy:ids";
+				break;
+		}
+	}
+
+	return $key;
+}
+
 //
 // Private
 //
Index: wp-includes/category-template.php
===================================================================
--- wp-includes/category-template.php	(revision 23294)
+++ wp-includes/category-template.php	(working copy)
@@ -1065,7 +1065,7 @@
 	$terms = get_object_term_cache( $post->ID, $taxonomy );
 	if ( false === $terms ) {
 		$terms = wp_get_object_terms( $post->ID, $taxonomy );
-		wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
+		wp_cache_add( $post->ID, $terms, term_cache_group( $taxonomy, 'relationships' ) );
 	}
 
 	$terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
