WordPress.org

Make WordPress Core

Ticket #2268: cache_option_non_existence.diff

File cache_option_non_existence.diff, 1.1 KB (added by markjaquith, 14 years ago)

Patch for trunk

  • wp-includes/functions.php

     
    203203function get_option($setting) {
    204204        global $wpdb;
    205205
     206        // prevent non-existent options from triggering multiple queries
     207        if ( true === wp_cache_get($setting, 'notoptions') )
     208                return false;
     209
    206210        $value = wp_cache_get($setting, 'options');
    207211
    208212        if ( false === $value ) {
     
    215219                if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
    216220                        $value = $row->option_value;
    217221                        wp_cache_set($setting, $value, 'options');
    218                 } else {
     222                } else { // option does not exist, so we must cache its non-existence
     223                        wp_cache_set($setting, true, 'notoptions');
    219224                        return false;
    220225                }
    221226        }
     
    274279                return true;
    275280        }
    276281
     282        if ( true === wp_cache_get($option_name, 'notoptions') )
     283                wp_cache_delete($option_name, 'notoptions');
     284
    277285        $_newvalue = $newvalue;
    278286        $newvalue = maybe_serialize($newvalue);
    279287