• Resolved Arun R Shenoy

    (@arunshenoy99)


    Hi team,

    I’m encountering an issue with transients. When I set a transient using set_transient(), it’s successfully stored in the database. I can see it in the wp_options table.

    But, when I try to retrieve it using get_transient() here, it returns false (or doesn’t fetch the value) only when the plugin is active. I added some logs to see what was happening in the above part of the code and this is what I found (Stored Token needs to match Token):

    [10-Nov-2025 14:32:37 UTC] Expired:
    [10-Nov-2025 14:32:37 UTC] Stored Token (from transient):
    [10-Nov-2025 14:32:37 UTC] Token:OGMzYTE5ZmYyMjNjNjg0NmIyMTJjN2ZhMWUzOWZjNDg5Mjc5YzFjY2UxNGMzYWNk

    As soon as I deactivate the plugin, the same code works perfectly and returns the expected value. Could you please help me understand why this might be happening? Is there a possibility that the plugin is overriding or clearing transients in some way?

    Thanks in advance for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author OllieJones

    (@olliejones)

    Thanks for the heads up about this.

    The way WordPress core works, transients are, when a persistent object cache is active, stored in that cache and retrieved from that cache, not the wp_options table. That’s a core feature, not a persistent object cache plugin feature.

    So, if you stored the transient, then activated this persistent object cache (or Till Kruess’s Redis Object Cache), you could not get a transient that was updated before activating it..

    Is that what you are doing? Please let me know. I do have a lot of testing that checks that transients function correctly and expire as specified.

    I, and Till, have to erase all transients from the wp_options table when deactivating the caches. That’s due to a strange bug in WooCommerce where a stale transient value causes confusion.

    (And, it might be possible for your quite short transient name to duplicate something in another plugin. I’ve been bitten by that, and now transients in code I write have absurdly long names containing my plugin name.)

    Thread Starter Arun R Shenoy

    (@arunshenoy99)

    Hi @olliejones, thanks for your response! I’ll check if any of these cases are occurring and get back to you soon.

    Thread Starter Arun R Shenoy

    (@arunshenoy99)

    Hi @olliejones I think I’ve been able to replicate my use case locally.

    Here’s what I did: I activated the plugin, set the transient directly in the database via MySQL, and then tried to fetch it in code using get_transient('sso_token'). I couldn’t retrieve the value, which is the same behavior I’m seeing in production (the hosting platform sets the value there and the plugin retrieves it using the code I linked). But, if I repeat the same process with the plugin deactivated, I can retrieve the transient value.

    Are you aware of this scenario where setting a transient directly in the database (via MySQL/Adminer/phpMyAdmin, etc.) while the plugin is active could cause retrieval to fail? is that expected? Thanks!

    Plugin Author OllieJones

    (@olliejones)

    Interesting question. You’re trying to set a transient by writing a row to the options table. You Can’t Do That™. Why not?

    When a persistent object cache is present, transients are neither written to nor read from the options table. Instead, they go directly into the persistent object cache. Check out this core code.

    https://github.com/WordPress/wordpress-develop/blob/6.8.3/src/wp-includes/option.php#L1540-L1543

    If you want your code to be compatible with persistent object caches, you’ll have to use set_transient and get_transient, and make no assumptions about where those transients are actually stored.

    Plugin Author OllieJones

    (@olliejones)

    And, your transients will all vanish when you activate or deactivate the persistent object cache plugin. (Due to the way the transient API is designed, code using transients must be prepared for them to vanish unpredictably.)

    Thread Starter Arun R Shenoy

    (@arunshenoy99)

    Ahh, got it, that makes perfect sense. We can go ahead and close this ticket now. Thanks a lot for all the help!

    I can confirm this issue. set_transient works and I can see the entry being stored into the APCu database, but when using get_transient it doesn’t return anything. It only happens if this plugin is activated. When it’s not, all works fine.

    I’ve discovered that the issue doesn’t happens if APCu is disabled, set to “false” in wp-config.php.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.