Index: src/wp-includes/class-wp-query.php
===================================================================
--- src/wp-includes/class-wp-query.php	(revision 40920)
+++ src/wp-includes/class-wp-query.php	(working copy)
@@ -472,7 +472,7 @@
 	 * @access public
 	 * @var bool
 	 */
-	 public $thumbnails_cached = false;
+	public $thumbnails_cached = false;
 
 	/**
 	 * Cached list of search stopwords.
@@ -574,42 +574,42 @@
 	public function fill_query_vars($array) {
 		$keys = array(
 			'error'
-			, 'm'
-			, 'p'
-			, 'post_parent'
-			, 'subpost'
-			, 'subpost_id'
-			, 'attachment'
-			, 'attachment_id'
-			, 'name'
-			, 'static'
-			, 'pagename'
-			, 'page_id'
-			, 'second'
-			, 'minute'
-			, 'hour'
-			, 'day'
-			, 'monthnum'
-			, 'year'
-			, 'w'
-			, 'category_name'
-			, 'tag'
-			, 'cat'
-			, 'tag_id'
-			, 'author'
-			, 'author_name'
-			, 'feed'
-			, 'tb'
-			, 'paged'
-			, 'meta_key'
-			, 'meta_value'
-			, 'preview'
-			, 's'
-			, 'sentence'
-			, 'title'
-			, 'fields'
-			, 'menu_order'
-			, 'embed'
+		, 'm'
+		, 'p'
+		, 'post_parent'
+		, 'subpost'
+		, 'subpost_id'
+		, 'attachment'
+		, 'attachment_id'
+		, 'name'
+		, 'static'
+		, 'pagename'
+		, 'page_id'
+		, 'second'
+		, 'minute'
+		, 'hour'
+		, 'day'
+		, 'monthnum'
+		, 'year'
+		, 'w'
+		, 'category_name'
+		, 'tag'
+		, 'cat'
+		, 'tag_id'
+		, 'author'
+		, 'author_name'
+		, 'feed'
+		, 'tb'
+		, 'paged'
+		, 'meta_key'
+		, 'meta_value'
+		, 'preview'
+		, 's'
+		, 'sentence'
+		, 'title'
+		, 'fields'
+		, 'menu_order'
+		, 'embed'
 		);
 
 		foreach ( $keys as $key ) {
@@ -1090,7 +1090,7 @@
 					'field' => 'slug',
 				);
 
- 				if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
+				if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
 					$q[$t->query_var] = wp_basename( $q[$t->query_var] );
 				}
 
@@ -1733,12 +1733,13 @@
 			$q['suppress_filters'] = false;
 
 		if ( !isset($q['cache_results']) ) {
-			if ( wp_using_ext_object_cache() )
-				$q['cache_results'] = false;
-			else
-				$q['cache_results'] = true;
+			$q['cache_results'] = true;
 		}
 
+		if ( ! isset( $q['update_post_cache'] ) ) {
+			$q['update_post_cache'] = $q['cache_results'];
+		}
+
 		if ( !isset($q['update_post_term_cache']) )
 			$q['update_post_term_cache'] = true;
 
@@ -1812,9 +1813,6 @@
 			case 'ids':
 				$fields = "{$wpdb->posts}.ID";
 				break;
-			case 'id=>parent':
-				$fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent";
-				break;
 			default:
 				$fields = "{$wpdb->posts}.*";
 		}
@@ -2780,39 +2778,33 @@
 		 */
 		$this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) );
 
-		if ( 'ids' == $q['fields'] ) {
-			if ( null === $this->posts ) {
-				$this->posts = $wpdb->get_col( $this->request );
+		if ( null === $this->posts && $q['cache_results'] ) {
+			global $wp_post_types;
+
+			$key          = md5( serialize( $this->request + $wp_post_types ) );
+			$last_changed = wp_cache_get_last_changed( 'posts' );
+			// If there is a taxonomy query, salt the cache key with terms last changed.
+			if ( ! empty( $q['tax_query'] ) ) {
+				$last_changed .= wp_cache_get_last_changed( 'terms' );
 			}
+			$cache_key   = "get_posts:$key:$last_changed";
+			$cache_value = wp_cache_get( $cache_key, 'posts' );
 
-			$this->posts = array_map( 'intval', $this->posts );
-			$this->post_count = count( $this->posts );
-			$this->set_found_posts( $q, $limits );
-
-			return $this->posts;
+			if ( false !== $cache_value ) {
+				$this->posts       = $cache_value['post_ids'];
+				$this->found_posts = $cache_value['found_posts'];
+			}
 		}
 
-		if ( 'id=>parent' == $q['fields'] ) {
-			if ( null === $this->posts ) {
-				$this->posts = $wpdb->get_results( $this->request );
-			}
+		if ( null === $this->posts ) {
 
-			$this->post_count = count( $this->posts );
-			$this->set_found_posts( $q, $limits );
-
-			$r = array();
-			foreach ( $this->posts as $key => $post ) {
-				$this->posts[ $key ]->ID = (int) $post->ID;
-				$this->posts[ $key ]->post_parent = (int) $post->post_parent;
-
-				$r[ (int) $post->ID ] = (int) $post->post_parent;
+			if ( "{$wpdb->posts}.ID" == $fields ) {
+				$split_the_query = true;
+			} else if ( "{$wpdb->posts}.*" == $fields ) {
+				$split_the_query = ( $old_request == $this->request &&  ! empty( $limits ) && $q['posts_per_page'] < 500 );
 			}
 
-			return $r;
-		}
 
-		if ( null === $this->posts ) {
-			$split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
 
 			/**
 			 * Filters whether to split the query.
@@ -2846,9 +2838,11 @@
 				$ids = $wpdb->get_col( $this->request );
 
 				if ( $ids ) {
-					$this->posts = $ids;
+					$this->posts      = array_map( 'intval', $ids );
 					$this->set_found_posts( $q, $limits );
-					_prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
+					if ( 'ids' != $q['fields'] ) {
+						_prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
+					}
 				} else {
 					$this->posts = array();
 				}
@@ -2858,6 +2852,19 @@
 			}
 		}
 
+		if ( 'ids' == $q['fields'] ) {
+			$this->post_count = count( $this->posts );
+			if ( $q['cache_results'] ) {
+				$cache_value = array(
+					'post_ids'    => $this->posts,
+					'found_posts' => $this->found_posts,
+				);
+				wp_cache_add( $cache_key, $cache_value, 'posts' );
+			}
+
+			return $this->posts;
+		}
+
 		// Convert to WP_Post objects.
 		if ( $this->posts ) {
 			$this->posts = array_map( 'get_post', $this->posts );
@@ -2875,6 +2882,15 @@
 			$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
 		}
 
+		if ( $q['cache_results'] && is_array( $this->posts ) ) {
+			$post_ids = wp_list_pluck( $this->posts, 'ID' );
+			$cache_value = array(
+				'post_ids'    => $post_ids,
+				'found_posts' => $this->found_posts,
+			);
+			wp_cache_add( $cache_key, $cache_value, 'posts' );
+		}
+
 		if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
 			/** This filter is documented in wp-includes/query.php */
 			$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
@@ -3011,11 +3027,12 @@
 		// of the type WP_Post and are filtered.
 		if ( $this->posts ) {
 			$this->post_count = count( $this->posts );
-
 			$this->posts = array_map( 'get_post', $this->posts );
 
-			if ( $q['cache_results'] )
+			// Prime post caches.
+			if ( $q['update_post_cache'] ) {
 				update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']);
+			}
 
 			$this->post = reset( $this->posts );
 		} else {
@@ -3027,6 +3044,19 @@
 			wp_queue_posts_for_term_meta_lazyload( $this->posts );
 		}
 
+
+		if ( 'id=>parent' == $q['fields'] ) {
+			$r = array();
+			foreach ( $this->posts as $key => $post ) {
+				$this->posts[ $key ]->ID          = (int) $post->ID;
+				$this->posts[ $key ]->post_parent = (int) $post->post_parent;
+
+				$r[ (int) $post->ID ] = (int) $post->post_parent;
+			}
+
+			return $r;
+		}
+
 		return $this->posts;
 	}
 
@@ -3406,14 +3436,14 @@
 	}
 
 	/**
- 	 * Is the query for an existing archive page?
- 	 *
- 	 * Month, Year, Category, Author, Post Type archive...
+	 * Is the query for an existing archive page?
 	 *
- 	 * @since 3.1.0
- 	 *
- 	 * @return bool
- 	 */
+	 * Month, Year, Category, Author, Post Type archive...
+	 *
+	 * @since 3.1.0
+	 *
+	 * @return bool
+	 */
 	public function is_archive() {
 		return (bool) $this->is_archive;
 	}
@@ -3605,10 +3635,10 @@
 			return true;
 
 		return isset( $queried_object->term_id ) &&
-			count( array_intersect(
-				array( $queried_object->term_id, $queried_object->name, $queried_object->slug ),
-				$term_array
-			) );
+		       count( array_intersect(
+			       array( $queried_object->term_id, $queried_object->name, $queried_object->slug ),
+			       $term_array
+		       ) );
 	}
 
 	/**
@@ -4055,8 +4085,8 @@
 			}
 			$multipage = 1;
 		} else {
-	 		$multipage = 0;
-	 	}
+			$multipage = 0;
+		}
 
 		/**
 		 * Fires once the post data has been setup.
