Index: wp-includes/load.php
===================================================================
--- wp-includes/load.php	(revision 22086)
+++ wp-includes/load.php	(working copy)
@@ -409,7 +409,7 @@
 		wp_cache_init();
 
 	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
-		wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
+		wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) );
 		wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
 	}
 }
Index: wp-includes/ms-blogs.php
===================================================================
--- wp-includes/ms-blogs.php	(revision 22087)
+++ wp-includes/ms-blogs.php	(working copy)
@@ -253,12 +253,7 @@
 	$blog_id = (int) $blog_id;
 	$details = get_blog_details( $blog_id, false );
 
-	wp_cache_delete( $blog_id , 'blog-details' );
-	wp_cache_delete( $blog_id . 'short' , 'blog-details' );
-	wp_cache_delete( md5( $details->domain . $details->path )  , 'blog-lookup' );
-	wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' );
-	wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' );
-	wp_cache_delete( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' );
+	clean_blog_cache( $details );
 
 	do_action( 'refresh_blog_details', $blog_id );
 }
@@ -317,6 +312,26 @@
 }
 
 /**
+ * Clean the blog cache
+ *
+ * @since 3.5.0
+ *
+ * @param stdClass $blog The blog details as returned from get_blog_details()
+ */
+function clean_blog_cache( $blog ) {
+	$blog_id = $blog->blog_id;
+	$domain_path_key = md5( $blog->domain . $blog->path );
+
+	wp_cache_delete( $blog_id , 'blog-details' );
+	wp_cache_delete( $blog_id . 'short' , 'blog-details' );
+	wp_cache_delete(  $domain_path_key, 'blog-lookup' );
+	wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
+	wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
+	wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' );
+	wp_cache_delete( $domain_path_key, 'blog-id-cache' );
+}
+
+/**
  * Retrieve option value for a given blog id based on name of option.
  *
  * If the option does not exist or does not have a value, then the return value
Index: wp-includes/ms-functions.php
===================================================================
--- wp-includes/ms-functions.php	(revision 22086)
+++ wp-includes/ms-functions.php	(working copy)
@@ -332,27 +332,27 @@
  *
  * @param string $domain
  * @param string $path Optional. Not required for subdomain installations.
- * @return int
+ * @return int 0 if no blog found, otherwise the ID of the matching blog
  */
 function get_blog_id_from_url( $domain, $path = '/' ) {
 	global $wpdb;
 
-	$domain = strtolower( $wpdb->escape( $domain ) );
-	$path = strtolower( $wpdb->escape( $path ) );
+	$domain = strtolower( $domain );
+	$path = strtolower( $path );
 	$id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
 
-	if ( $id == -1 ) { // blog does not exist
+	if ( $id == -1 ) // blog does not exist
 		return 0;
-	} elseif ( $id ) {
-		return (int)$id;
-	}
+	elseif ( $id )
+		return (int) $id;
 
-	$id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" );
+	$id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) );
 
-	if ( !$id ) {
+	if ( ! $id ) {
 		wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
-		return false;
+		return 0;
 	}
+
 	wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
 
 	return $id;
Index: wp-admin/includes/ms.php
===================================================================
--- wp-admin/includes/ms.php	(revision 22086)
+++ wp-admin/includes/ms.php	(working copy)
@@ -55,14 +55,13 @@
 	global $wpdb, $current_site;
 
 	$switch = false;
-	if ( $blog_id != $wpdb->blogid ) {
+	if ( get_current_blog_id() != $blog_id ) {
 		$switch = true;
 		switch_to_blog( $blog_id );
-		$blog = get_blog_details( $blog_id );
-	} else {
-		$blog = $GLOBALS['current_blog'];
 	}
 
+	$blog = get_blog_details( $blog_id );
+
 	do_action( 'delete_blog', $blog_id, $drop );
 
 	$users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
@@ -81,7 +80,6 @@
 		$drop = false;
 
 	if ( $drop ) {
-
 		$drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
 
 		foreach ( (array) $drop_tables as $table ) {
@@ -122,6 +120,8 @@
 			if ( $dir != $top_dir)
 			@rmdir( $dir );
 		}
+
+		clean_blog_cache( $blog );
 	}
 
 	if ( $switch )
