[wp-hackers] Nasty get_option()/get_settings() bug

Mark Jaquith mark.wordpress at txfx.net
Wed Jan 11 11:55:35 GMT 2006


Thought I'd open this bug up for discussion here.  This is a new bug  
that was introduced with WP 2.0's option caching.

http://trac.wordpress.org/ticket/2268

The short version, is that get_settings() ( alias of get_option() )  
caches non-existent options as FALSE.  So if i do get_option 
('this_option_does_not_exist'); it will get cached as the result from  
the $wpdb query... which is FALSE.  Now, when asking for this option  
again, the following condition is evaluated, after setting $value to  
the value of the option according to the options cache.

> if ( false === $value ) {

And if that condition is true, it tries the query again.  So, if I do  
get_option('this_option_does_not_exist'); 100 times on a page load...  
I'll get 100 identical queries.  Ugh.

So what we need to do is come up with a way to discriminate between  
"option isn't in cache" (and therefore, make the query) and "option's  
non-existence has been cached" (and therefore don't make the query,  
because we know it doesn't exist).

I was thinking about having wp_cache_get() return NULL for values not  
in the option cache, so that FALSE can mean FALSE, as it would if you  
had queried the database for the option... but I'm open to suggestions.

--
Mark Jaquith
http://txfx.net/




More information about the wp-hackers mailing list