Index: src/wp-includes/ms-settings.php
===================================================================
--- src/wp-includes/ms-settings.php	(revision 27627)
+++ src/wp-includes/ms-settings.php	(working copy)
@@ -124,9 +124,11 @@
 		if ( $current_blog && $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) {
 			$current_site->blog_id = $current_blog->blog_id;
 		} else {
-			// @todo we should be able to cache the blog ID of a network's main site easily.
-			$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
-				$current_site->domain, $current_site->path ) );
+			if ( ! $current_site->blog_id = wp_cache_get( 'network_' . $current_site->id . '_blog_id', 'site-options' ) ) {
+				$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
+					$current_site->domain, $current_site->path ) );
+				wp_cache_add( 'network_' . $current_site->id . '_blog_id', $current_site->blog_id, 'site-options' );
+			}
 		}
 	}
 
