WordPress `get_transient()` returns stale value
09:07 17 Jan 2024

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?

php ajax wordpress server-sent-events