Index: src/wp-includes/option.php
===================================================================
--- src/wp-includes/option.php	(revision 25114)
+++ src/wp-includes/option.php	(working copy)
@@ -244,19 +244,20 @@
 	$newvalue = maybe_serialize( $newvalue );
 
 	do_action( 'update_option', $option, $oldvalue, $_newvalue );
-	if ( ! defined( 'WP_INSTALLING' ) ) {
-		$alloptions = wp_load_alloptions();
-		if ( isset( $alloptions[$option] ) ) {
-			$alloptions[$option] = $newvalue;
-			wp_cache_set( 'alloptions', $alloptions, 'options' );
-		} else {
-			wp_cache_set( $option, $newvalue, 'options' );
-		}
-	}
 
 	$result = $wpdb->update( $wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) );
 
 	if ( $result ) {
+		if ( ! defined( 'WP_INSTALLING' ) ) {
+			$alloptions = wp_load_alloptions();
+			if ( isset( $alloptions[ $option ] ) ) {
+				$alloptions[ $option ] = $newvalue;
+				wp_cache_set( 'alloptions', $alloptions, 'options' );
+			} else {
+				wp_cache_set( $option, $newvalue, 'options' );
+			}
+		}
+
 		do_action( "update_option_{$option}", $oldvalue, $_newvalue );
 		do_action( 'updated_option', $option, $oldvalue, $_newvalue );
 		return true;
@@ -316,26 +317,27 @@
 	$value = maybe_serialize( $value );
 	$autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
 	do_action( 'add_option', $option, $_value );
-	if ( ! defined( 'WP_INSTALLING' ) ) {
-		if ( 'yes' == $autoload ) {
-			$alloptions = wp_load_alloptions();
-			$alloptions[$option] = $value;
-			wp_cache_set( 'alloptions', $alloptions, 'options' );
-		} else {
-			wp_cache_set( $option, $value, 'options' );
-		}
-	}
 
-	// This option exists now
-	$notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
-	if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
-		unset( $notoptions[$option] );
-		wp_cache_set( 'notoptions', $notoptions, 'options' );
-	}
-
 	$result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $value, $autoload ) );
 
 	if ( $result ) {
+		if ( ! defined( 'WP_INSTALLING' ) ) {
+			if ( 'yes' == $autoload ) {
+				$alloptions = wp_load_alloptions();
+				$alloptions[ $option ] = $value;
+				wp_cache_set( 'alloptions', $alloptions, 'options' );
+			} else {
+				wp_cache_set( $option, $value, 'options' );
+			}
+		}
+
+		// This option exists now
+		$notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
+		if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
+			unset( $notoptions[ $option ] );
+			wp_cache_set( 'notoptions', $notoptions, 'options' );
+		}
+
 		do_action( "add_option_{$option}", $option, $_value );
 		do_action( 'added_option', $option, $_value );
 		return true;
