Does set_transient() overwrite/update transient option with same key?
Yes, key (prefixed with string identifying it as transient) is used as option name when value is inserted in database.
Yes, key (prefixed with string identifying it as transient) is used as option name when value is inserted in database.
Forgot I could go this route: $wpdb->query( “DELETE FROM `$wpdb->options` WHERE `option_name` LIKE (‘_transient_galleries_%’)” );
Yes, social counts are a great use case for using transients. Aside from the slow page loading, as you mentioned, this will also help prevent you from blowing through API limits if the external requests are being made on every page load. Let’s say you have it set to cache for 30 minutes and the … Read more
Yes, delete_expired_transients is a cron event that runs once per day and the function delete_expired_transients() is automatically called when the cron event runs — see wp-includes/default-filters.php. So you do not need to call the function manually like you did in your my_custom_fn() function. And if you use a plugin like WP Crontrol, you can easily … Read more
Transients expire on their own. No need to unset them. And to call wp-cron manually is simple. Just define DISABLE_WP_CRON to true in the wp-config file to disable the normal cron spawning process. Then make your cron system hit wp-cron.php manually every so often to process pending jobs. There is no other special trick that … Read more
The db query would look like this: SELECT `option_name` AS `name`, `option_value` AS `value` FROM $wpdb->options WHERE `option_name` LIKE ‘%transient_%’ ORDER BY `option_name` To sort the results by their function (site transients, timeouts) use a function like this: add_action( ‘shutdown’, function(){ global $wpdb; $sql = “SELECT `option_name` AS `name`, `option_value` AS `value` FROM $wpdb->options WHERE … Read more
When and how to use transients or the object cache is a bit tricky and site-dependent. Here’s the breakdown: When not using a persistent object cache (like memcached): Transients are stored in the database Objects in the object cache are only cached for the duration of the page request. When using a persistent object cache … Read more
TL;DR WordPress part of transient handling is solid, everything is pretty precise Transients use object cache instead of data store for non-default implementations It means that some back-end cache systems get rid of cache that hasn’t been accessed recently Bottom line: it’s not WordPress fault, it only depends on how your back-end cache is set … Read more
Transients are just database keys that expire. It’s like telling WordPress you want it to remember a certain piece of information, but for a limited time. In general, transients are accessible to PHP through any request. But since they’re server-side, transients are only exposed to front-end users if you as the developer expose them. A … Read more
Is this ok or should I just store it in an array form so I can just directly access it without using json_decode? In your case store it directly means store it serialized. Because $data is an array and cannot be stored as is, but converted to a string. Even if you access it directly … Read more