Ecommerce Shopify WordPress Discussion

WordPress `get_transient()` returns stale value

I'm building a WordPress plugin that uses server-sent events to update a page when data changes. Here's a snippet from that code: while ( true ) { // Send the updates to the client. $this->send_sse_event( 'updates_push', get_transient( 'name_of_the_transient' ); sleep( 5 ); if ( connection_aborted() ) { break; } } The problem is that the events sent from that script hold stale data... meaning when another request to some PHP script changes the value of the transient, the server-sent event still sends the old value until I refresh the page. Any ideas on how to solve this?
The problem seems to be default object cache of the managed hosting provider. After a call to wp_cache_flush() the transient returns the correct data. Therefore, the solution is to exclude the transient from caching/revalidate the cache for that transient before you use its value.

January 20, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.