Make WordPress Core

Opened 16 years ago

Closed 14 years ago

#15548 closed defect (bug) (fixed)

Cache inconsistencies between get_option and get_blog_option

Reported by: mwidmann Owned by:
Priority: normal Milestone: 3.5
Component: Multisite Version: 3.0.1
Severity: normal Keywords: caching memcache has-patch
Cc: Focuses:

Description

When an option is updated for a blog update_option calls wp_cache_set to update the cache for that option.

The problem comes when the option is accessed through get_blog_option from another site. There the cache never gets updated (unless the caching - in our case memcached - is recycled.

Steps to reproduce, I'm updating the admin_email, so be sure to change it back afterwards:

echo "fetching using get_blog_option<br>";
echo get_blog_option( 6, 'admin_email' );

switch_to_blog( 6 );
echo "<br>fetching using get_option before update<br>";
echo get_option( 'admin_email' );
echo "<br>updating...<br>";
update_option( 'admin_email', 'new-value@email.com' );
echo "<br>fetching using get_option after update<br>";
echo get_option( 'admin_email' );
restore_current_blog();

echo "<br>fetching using get_blog_option after uptdate<br>";
echo get_blog_option( 6, 'admin_email' );

The output will look like something similar to this:

fetching using get_blog_option
old-value@email.com
fetching using get_option before update
new-value@email.com
updating...

fetching using get_option after update
new-value@email.com
fetching using get_blog_option after uptdate
old-value@email.com

If no caching is enabled than - of course - this issue doesn't come up as the value is always fetched form the database.

The best solution most probably would be to modify the either hook into update_option and delete_option actions from ms-blogs.php and then update or delete the value based on the given option.

Change History (9)

#1 @mwidmann
16 years ago

Here's a way around this limitation, I load it from a mu-plugin.

add_action( 'update_option', 'vmh_update_option', 11, 3 );
add_action( 'delete_option', 'vmh_delete_option', 11, 2 );

function vmh_update_option( $option, $oldvalue, $newvalue ) {
	global $blog_id;

	if ( is_multisite() ) {
		$key = $blog_id."-".$option."-blog_option";
		$value = wp_cache_get( $key, "site-options" );
		if ( FALSE !== $value ) {
			wp_cache_set( $key, $newvalue, "site-options" );
		}
	}
}
function vmh_delete_option( $option, $oldvalue ) {
	global $blog_id;

	if ( is_multisite() ) {
		$key = $blog_id."-".$option."-blog_option";
		wp_cache_delete( $key, "site-options" );
	}
}

#2 @scribu
16 years ago

Related: #14992

#3 @markjaquith
16 years ago

  • Milestone Awaiting ReviewFuture Release
  • Type defect (bug)enhancement

#4 @SergeyBiryukov
15 years ago

  • Keywords caching, memcache → caching memcache

Closed #19822 as a duplicate. Has a patch: ticket:19822:patch.diff.

#5 @mohanjith
15 years ago

  • Cc moha@… added
  • Type enhancementdefect (bug)

#6 @uglyrobot
15 years ago

  • Cc aaron@… added
  • Keywords has-patch added
  • Version 3.0.13.3.1

#7 @SergeyBiryukov
15 years ago

  • Version 3.3.13.0.1

Version number indicates when the bug was initially introduced/reported.

#8 @scribu
14 years ago

  • Milestone Future Release3.5

This should be fixed as of [21357].

#9 @scribu
14 years ago

  • Resolutionfixed
  • Status newclosed
Note: See TracTickets for help on using tickets.