WordPress transients, Object Cache, and so on …

[ad_1]

Using WordPress transients in your plugin as a cache is typically a no-brainer. You set a transient, retrieve it later, and if it has expired, you do whatever you did before to re-create it. You don’t need to care where and/or how it’s stored. So far, so good.

But if you want to perform “mass actions” on your transients, you end up in a bit of a pickle, unless I’m completely off:

I create transients with my\_special\_prefix\_nnnn where nnnn is a key of sorts, the transient is (of course) given a value, and an expiration time. Retrieving them one at a time, when the key (nnnn) is known is no problem.

If I want to find all my\_special\_prefix\_\* transients, I can perform a query directly against the WordPress database. IF the transients are stored there. But if the site owner has installed an Object Cache plugin, to utilize redis, memcached, etc, this won’t (obviously) work.

Any suggestions?

AFAIK, there’s no way to fetch a range of transients with any WordPress API call. And there’s no way to know how/where the transient is stored, via the WordPress API.

I may want to find “wilrdcard” transients when uninstalling the plugin, deactivating the plugin, and/or to reset a “cache”. Using WP options may, of course, work, but then you end up having to build a layer on top of the options interface, much like the transient functions …

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer