get_option() aka get_settings() does not work well when the option queried does not exist. The result ( FALSE ) gets cached to the options cache, but every subsequent time the option is called, the cache is ignored, and the query is re-run. I've seem people run up over a hundred queries on some pages because of multiple calls to get the same option.
Note my comment in this code:
function get_settings($setting) {
global $wpdb;
$value = wp_cache_get($setting, 'options');
// !!!!!!!!!!!!!!!!!!!!
// this line below is the problem. An option that does not exist will === false, because it is stored
// in the cache as false. And so, the query is run again and again
if ( false === $value ) {
if ( defined('WP_INSTALLING') )
$wpdb->hide_errors();
$row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");
if ( defined('WP_INSTALLING') )
$wpdb->show_errors();
if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
$value = $row->option_value;
wp_cache_set($setting, $value, 'options');
} else {
return false;
}
}
Basically, we need a way to discriminate between "option isn't in cache" and "option's non-existence has been cached." I'm open to suggestions.