plugins – Managing and deleting transients with dynamically generated transient names
Let’s say I have access to a remote API that stores car data, and I want to be able to place car information box(es) into posts using a shortcode. The shortcode fetches JSON data with wp_remote_get() and server-side renders the HTML using the fetched data.
It seems using the transients API would make this performant, as performing multiple API calls on page load would be slow. Because the data changes infrequently, the expiration time would be set to a day. For the transient key, I would use a unique car ID or perhaps the remote API endpoint.
However, there are times you want the data to be updated immediately, and not wait for the transient to expire. So I want to add a function on the admin dashboard that lets users delete transients.
What would be a good way to manage transients, e.g. delete a single or all transients related to my plugin? It seems I need to keep a separate list of transients I have created somewhere, maybe using the options API. Is there any recommended approach for managing transients with dynamically generated names?