Index: src/wp-includes/class-wp-term-query.php
===================================================================
--- src/wp-includes/class-wp-term-query.php	(revision 40916)
+++ src/wp-includes/class-wp-term-query.php	(working copy)
@@ -585,33 +585,18 @@
 
 		$selects = array();
 		switch ( $args['fields'] ) {
-			case 'all':
-			case 'all_with_object_id' :
-			case 'tt_ids' :
-			case 'slugs' :
-				$selects = array( 't.*', 'tt.*' );
-				if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) {
-					$selects[] = 'tr.object_id';
-				}
-				break;
-			case 'ids':
-			case 'id=>parent':
-				$selects = array( 't.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy' );
-				break;
-			case 'names':
-				$selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy' );
-				break;
 			case 'count':
 				$orderby = '';
 				$order = '';
 				$selects = array( 'COUNT(*)' );
 				break;
-			case 'id=>name':
-				$selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' );
-				break;
-			case 'id=>slug':
-				$selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' );
+			default:
+				$selects = array( 't.*', 'tt.*' );
+				if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) {
+					$selects[] = 'tr.object_id';
+				}
 				break;
+
 		}
 
 		$_fields = $args['fields'];
@@ -672,42 +657,80 @@
 
 		$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
 
-		// $args can be anything. Only use the args defined in defaults to compute the key.
-		$key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
+		// $args can be anything. Only use the args defined in defaults to compute the key;
+		$_args = wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ); var_dump($_args);
+		if ( 'count' != $_fields ) {
+			unset( $_args['fields'] );
+		}
+		$key = md5( serialize( $_args ) . serialize( $taxonomies ) . $this->request );
 		$last_changed = wp_cache_get_last_changed( 'terms' );
 		$cache_key = "get_terms:$key:$last_changed";
 		$cache = wp_cache_get( $cache_key, 'terms' );
 		if ( false !== $cache ) {
-			if ( 'all' === $_fields ) {
-				$cache = array_map( 'get_term', $cache );
+			$_terms = array();
+			if ( ! in_array( $_fields, array( 'ids', 'count' ) ) ) {
+				$terms = array_map( 'get_term', $cache );
+				if ( 'id=>parent' == $_fields ) {
+					foreach ( $terms as $term ) {
+						$_terms[ $term->term_id ] = $term->parent;
+					}
+				}  elseif ( 'tt_ids' == $_fields ) {
+					foreach ( $terms as $term ) {
+						$_terms[] = (int) $term->term_taxonomy_id;
+					}
+				} elseif ( 'names' == $_fields ) {
+					foreach ( $terms as $term ) {
+						$_terms[] = $term->name;
+					}
+				} elseif ( 'slugs' == $_fields ) {
+					foreach ( $terms as $term ) {
+						$_terms[] = $term->slug;
+					}
+				} elseif ( 'id=>name' == $_fields ) {
+					foreach ( $terms as $term ) {
+						$_terms[ $term->term_id ] = $term->name;
+					}
+				} elseif ( 'id=>slug' == $_fields ) {
+					foreach ( $terms as $term ) {
+						$_terms[ $term->term_id ] = $term->slug;
+					}
+				} else {
+					$_terms = $terms;
+				}
+			} else {
+				$_terms = $cache;
 			}
 
-			$this->terms = $cache;
+			$this->terms = $_terms;
 			return $this->terms;
 		}
 
 		if ( 'count' == $_fields ) {
 			$count = $wpdb->get_var( $this->request );
 			wp_cache_set( $cache_key, $count, 'terms' );
+
 			return $count;
 		}
 
-		$terms = $wpdb->get_results( $this->request );
-		if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) {
-			update_term_cache( $terms );
-		}
+		$terms    = $wpdb->get_results( $this->request );
+		$term_ids = wp_list_pluck( $terms, 'term_id' );
+		$term_ids = array_map( 'intval', $term_ids );
+
+		update_term_cache( $terms );
+		$terms = array_map( 'get_term', $terms );
 
 		// Prime termmeta cache.
 		if ( $args['update_term_meta_cache'] ) {
-			$term_ids = wp_list_pluck( $terms, 'term_id' );
 			update_termmeta_cache( $term_ids );
 		}
 
 		if ( empty( $terms ) ) {
 			wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS );
+
 			return array();
 		}
 
+
 		if ( $child_of ) {
 			foreach ( $taxonomies as $_tax ) {
 				$children = _get_term_hierarchy( $_tax );
@@ -758,7 +781,7 @@
 				}
 
 				$_tt_ids[ $term->term_id ] = 1;
-				$_terms[] = $term;
+				$_terms[]                  = $term;
 			}
 
 			$terms = $_terms;
@@ -808,13 +831,12 @@
 			}
 		}
 
-		wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS );
 
-		if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) {
-			$terms = array_map( 'get_term', $terms );
-		}
+		wp_cache_add( $cache_key, $term_ids, 'terms', DAY_IN_SECONDS );
+
 
 		$this->terms = $terms;
+
 		return $this->terms;
 	}
 
Index: src/wp-includes/class-wp-term.php
===================================================================
--- src/wp-includes/class-wp-term.php	(revision 40916)
+++ src/wp-includes/class-wp-term.php	(working copy)
@@ -134,14 +134,17 @@
 
 		// If there isn't a cached version, hit the database.
 		if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) {
+
 			// Grab all matching terms, in case any are shared between taxonomies.
 			$terms = $wpdb->get_results( $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 t.term_id = %d", $term_id ) );
 			if ( ! $terms ) {
 				return false;
 			}
+			$_term = false;
 
 			// If a taxonomy was specified, find a match.
 			if ( $taxonomy ) {
+
 				foreach ( $terms as $match ) {
 					if ( $taxonomy === $match->taxonomy ) {
 						$_term = $match;
