Support » Developing with WordPress » Force get_option to read from the DB instead of cache

  • Resolved Arun Basil Lal

    (@arunbasillal)


    I have a plugin with a bulk updater that loops through all images. Currently the bulk updater runs in the browser and makes ajax calls. I am keeping track of the progress by storing a progress indicator (a number) in the database.

    During each run, the previous progress indicator is read, incremented by one, and saved back to the database.

    On servers with object caching enabled, the data that is being read is the cached value and not the one saved in the database. This causes issues sometimes where the same image keeps on getting updated instead of progressing to the next.

    Any idea how to solve this? Please suggest a better solution too, if there is one.

    Currently I am using get_option to read the saved number and update_option to write the updated number back into the database.

    Side note, I found this thread with some ideas, but none of them seems to be comprehensive – https://wordpress.stackexchange.com/questions/100040/can-i-force-get-option-to-go-back-to-the-db-instead-of-cache

    Thanks in advance for your time.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Would your process be able to save its progress as a session var instead of the DB? If the process is managed through a browser, you could instead save progress in a cookie.

    If you need to save the value in the DB, your best option is to read/write directly using the global $wpdb connection object.

    Thread Starter Arun Basil Lal

    (@arunbasillal)

    Thank you for your answer @bcworkz

    I can very well go with a cookie / session var based approach for my use case. I think this would be much more efficient too for rapidly updating data.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.