WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#4540 closed defect (bug) (wontfix)

wp_cache_delete don't work with option autoloaded

Reported by: xorax Owned by: westi
Milestone: Priority: normal
Severity: major Version: 2.2
Component: General Keywords: cache database options reporter-feedback
Focuses: Cc:

Description

WP_Object_Cache::delete not remove the cache of an option set with autoload property.

So wp_cache_delete not work with the options autoloaded.

And so, there is no others way exepts get the 'alloptions' cache, delete manualy the key of the option, and reset the cache of 'alloptions'.

for example :

add_option('myoption','myvalue') //imply the autoload param is 'yes'
// the cache of myoption is set in the group 'alloptions'

// simulation of a modification made by an other script :
$wpdb->query("UPDATE $wpdb->options SET option_value = 'mynewvalue' WHERE option_name = 'myoption'");

//do nothing because myoption is not cached in the group 'options'
wp_cache_delete('myoption','options');
echo get_option('myoption'); // output myvalue and not mynewvalue

//the real cache of myoption is now really deleted
$alloptions = wp_load_alloptions();
if ( isset($alloptions['readthis_posts2get']) ) {
  unset($alloptions['readthis_posts2get']);
  wp_cache_set('alloptions', $alloptions, 'options');
}

echo get_option('myoption'); //output mynewvalue

All plugins which used the wp_cache_delete function in WP < 2.2 don't work now.

Change History (4)

comment:1 westi7 years ago

  • Keywords reporter-feedback added
  • Owner changed from anonymous to westi
  • Status changed from new to assigned

Why are you accessing wp_cache_delete and wp_cache_set directly and not just using options api?

Does this work correctly if you use add_options/delete_option/update_option etc.

comment:2 westi7 years ago

  • Summary changed from wp_cahce_delete don't work with option autoloaded to wp_cache_delete don't work with option autoloaded

comment:3 xorax7 years ago

I view an error in my code example, replace :

$alloptions = wp_load_alloptions();
if ( isset($alloptions['readthis_posts2get']) ) {
  unset($alloptions['readthis_posts2get']);
  wp_cache_set('alloptions', $alloptions, 'options');
}

by

$alloptions = wp_load_alloptions();
if ( isset($alloptions['myoption']) ) {
  unset($alloptions['myoption']);
  wp_cache_set('alloptions', $alloptions, 'options');
}

This work correctly if I use options API. But, in certain case, you must delete only the cache and there is no function for that.

I'm french so it's very hard to explain why...

but, for example, if you want to traduct your post with a SOAP in a plugin.
you set value of an option 'confirm' to 'no' in the thread of the plugin.
now you call SOAP, the service get your post in other thread and you set the value of the option 'confirm' to 'ok' for verified the service has really get your post.
now, in your plugin thread, if the value of 'confirm' is 'ok', the SOAP has run correctly, else there was an error.

did I explain correctly ?

comment:4 markjaquith7 years ago

  • Milestone 2.2.2 deleted
  • Resolution set to wontfix
  • Status changed from assigned to closed

You could just have it give a response when it gets the post. In any case, if the options API doesn't work, you'll have to use something else to track this. The caching functions aren't intended for use in plugins.

Note: See TracTickets for help on using tickets.