Title: Object cache bug?
Last modified: June 16, 2025

---

# Object cache bug?

 *  Resolved [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 2 weeks ago](https://wordpress.org/support/topic/object-cache-bug-3/)
 * Hi, I’m working on a small plugin that needs to distinguish between an empty 
   option and an option that is not set. This is normally done reliably by looking
   at what `get_option()` returns: an empty value ” (when empty) or the boolean 
   false (when not found).
 * I have noticed that when Object caching (in my case via Redis socket, have not
   tested other scenarios) is on, this behavior is not always consistent.
 * When the empty value is fetched from the DB and stored by the cache, the response
   is always ” (correct) but right after saving the empty option from admin, `get_option('
   my_setting' )` starts responding with `false` instead of ” (not correct!).
 * Only after a cache purge, the correct response is back. Or if I disable the Object
   caching on the admin entirely, of course…
 * Is this a known issue?

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/object-cache-bug-3/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/object-cache-bug-3/page/2/?output_format=md)

 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18516223)
 *     ```wp-block-code
       <?phprequire('./wp-load.php');update_option('test_option', 'test_value');echo '<pre>' . var_dump(get_option('test_option')) . '</pre>';echo "update to empty<br><br>";update_option('test_option', '');echo '<pre>' . var_dump(get_option('test_option')) . '</pre>';
       ```
   
 * above test code returns
 *     ```wp-block-code
       string(10) "test_value"update to emptystring(0) ""
       ```
   
 * seems alright on me
 * please explain a bit what exactly did you do ?
 * a sample code would be great help though.
    -  This reply was modified 11 months, 1 week ago by [qtwrk](https://wordpress.org/support/users/qtwrk/).
    -  This reply was modified 11 months, 1 week ago by [qtwrk](https://wordpress.org/support/users/qtwrk/).
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18516495)
 * Okay I found what is going “wrong”:
 * In the plugin, I have a sanitize routine that returned false when the option 
   is empty. In normal operations, without Object cache, this is stored in the DB
   as an empty option. Then fetched again, it shows an empty result (not false) 
   but apparently when added to the object cache, this conversion from false to 
   empty does **not** take place.
 * So for testing purposes, try:
 *     ```wp-block-code
       <?phprequire('./wp-load.php');update_option( 'test_option', 'test_value' );update_option( 'test_option', false );var_dump( get_option( 'test_option' ) );
       ```
   
 * I have not tested this exact code sample but I suspect that with the object cache
   active, the dumped variable shows `bool(false)`, while without object cache or
   after a purge it will be `string(0) ""`.
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18516511)
 * the one you provided , show `bool false` on me , with and without object cache
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18516835)
 * After `update_option( 'test_option', false )` the option is stored in the database
   as an empty value, correct? Then `get_option( 'test_option' )` should not be 
   returning `false` but `''`. It should only return false if the option is not 
   found in the database…
 * The only difference between the test code and my plugin is that the option’s 
   autoload is set to auto-on (via a `wp_default_autoload_value` filter) … Please
   try with the autoload flag:
 *     ```wp-block-code
       update_option( 'test_option', 'test_value', true );update_option( 'test_option', false, true );var_dump( get_option( 'test_option' ) );
       ```
   
 * I tested this and it does show different results with and without the object 
   cache. At least on my dev site.
 * Hope this helps 🙂
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18516841)
 * with your latest code, I tested again , on a clean, new installed WP (no LiteSpeed
   plugin installed) , it still return bool false … 🧐
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18516902)
 * That _is_ weird. Is the option actually in the DB?
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18516904)
 * yes, I looked in DB, it’s there and empty , have you tried on a clean wp ? what
   does it show to you ?
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18520160)
 * Interesting…
 * Try this:
 *     ```wp-block-code
       update_option( 'test_option_1', 'test_value' );update_option( 'test_option_1', false );var_dump( get_option( 'test_option_1' ) );update_option( 'test_option_2', 'test_value', true );update_option( 'test_option_2', false, true );var_dump( get_option( 'test_option_2' ) );update_option( 'test_option_3', 'test_value', false );update_option( 'test_option_3', false, false );var_dump( get_option( 'test_option_3' ) );  
       ```
   
 * My result are:
 *     ```wp-block-code
       bool(false) bool(false) string(0) ""
       ```
   
 * So I would guess the inconsistency is within WordPress itself, not the object
   caching?
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18520179)
 *     ```wp-block-code
       bool(false) bool(false) string(0) ""
       ```
   
 * okay …. this set of code gives me this result , with and without object cache…
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18520206)
 * Even more interesting:
 *     ```wp-block-code
       var_dump( get_option( 'test_option_1' ) );update_option( 'test_option_1', 'test_value' );update_option( 'test_option_1', false );var_dump( get_option( 'test_option_1' ) );var_dump( get_option( 'test_option_2' ) );update_option( 'test_option_2', 'test_value', true );update_option( 'test_option_2', false, true );var_dump( get_option( 'test_option_2' ) );var_dump( get_option( 'test_option_3' ) );update_option( 'test_option_3', 'test_value', false );update_option( 'test_option_3', false, false );var_dump( get_option( 'test_option_3' ) );
       ```
   
 * Gives:
 *     ```wp-block-code
       string(0) "" bool(false) string(0) "" bool(false) string(0) "" string(0) ""
       ```
   
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18520210)
 * So it’s in the WP core options cache where the inconsistency occurs…
 * Anyway, not an object cache issue. Thanks for looking into this with me 🙂
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18520211)
 *     ```wp-block-code
       update_option( 'test_option_1', 'test_value' );update_option( 'test_option_1', false );var_dump( get_option( 'test_option_1' ) );
       ```
   
 * if I do this , it gives bool false , if I do
 *     ```wp-block-code
       #update_option( 'test_option_1', 'test_value' );   # no update on this one  update_option( 'test_option_1', false );var_dump( get_option( 'test_option_1' ) );
       ```
   
 * then it gives string “”
 * it just looks like it doesn’t like the way that you update the same option multiple
   times in same request ?
    -  This reply was modified 11 months, 1 week ago by [qtwrk](https://wordpress.org/support/users/qtwrk/).
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18520213)
 * > it just looks like it doesn’t like the way that you update the same option 
   > in same request ?
 * Indeed. See my answer just before where the code starts with getting the option
   from the DB and then updating with different dump…
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18520217)
 * I guess that with the Object cache on, this “odd” behavior is made persistent
   across requests. Not the object caches fault, just that it made it apparent (
   I’m not updating the option twice in one request but only after Save on the options
   page)
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/#post-18521866)
 * Created ticket on [https://core.trac.wordpress.org/ticket/63610](https://core.trac.wordpress.org/ticket/63610)

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/object-cache-bug-3/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/object-cache-bug-3/page/2/?output_format=md)

The topic ‘Object cache bug?’ is closed to new replies.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * Last activity: [11 months, 1 week ago](https://wordpress.org/support/topic/object-cache-bug-3/page/2/#post-18521871)
 * Status: resolved