Is there any way to guarantee that when I call get_option I will definitely get the value from the database and not from cache?
3 comments
Comments are closed.
Is there any way to guarantee that when I call get_option I will definitely get the value from the database and not from cache?
Comments are closed.
You could delete an existing cache for your option before you call
get_option()
:Using the wp_cache_delete() technic showcased by toscho, you also have to make sure your option is not on autoload. If your option is autoloaded, it’ll be part of the
alloptions
cache so you won’t be able to clear it individually.So make sure to use the following format when you set/update your option if you want to be able to clear it from the cache:
update_option() documentation
Bit old question but I’ll add my piece of information.
I’m using WP REDIS CACHE and notified that some of my
get_option
were returning a cached value, instead of the real DB value. I tried @fuxia solution, but I guess this concerns autoloading. And REDIS cache was applying cache on a “lower level”.I ended up with something to directly get some of my option from DB so I’m sure the value is correct: (in this example, my option name is
my_option_name
)see pre_get_option