How Transients are stored

This page’s content is still “work in progress” – please bear that in mind whilst reading

As previously mentioned, Transients are stored in WordPress’ options table. To identify the options record as a Transient it is prefixed by one of the following, depending on whether you’re using the multisite function or not…

_transient_*
_site_transient_*

This record is used to store the Transient value. If your Transient is set to timeout then a second record will be added to store the timeout value – they have one of the following prefixes…

_transient_timeout_*
_site_transient_timeout_*

So, an expiring Transient that you may name my_transient, written using the set_transient function on a non-multisite, would be stored on wp_options as two records named…

_transient_my_transient
_transient_timeout_my_transient

It would also be incorrect to assume the table that these are stored in is wp_options as, in the case of a multisite, wp_sitemeta is used instead (wp_options is used to store the network-level Transients as created by set_site_transient function).

Transients & Object Cache

Also of note is that Transients are inherently sped up by caching plugins, where normal Options are not. A memcached plugin, for example, would make WordPress store transient values in fast memory instead of in the database. For this reason, transients should be used to store any data that is expected to expire, or which can expire at any time. Transients should also never be assumed to be in the database, since they may not be stored there at all.

WordPress Codex

If you’re making use of an Object Cache, such as Memcache, then WordPress does some pretty weird and wonderful things with how it handles Transients (and, as mentioned above, it doesn’t do this with Options).

  • First of all, do you have a persistent cache? That’s where, well, it persists and doesn’t get lost after every page load. Memcached is persistent, for example.
  • If you don’t have persistent cache then WordPress stores Transient data both in that cache but, also,  in the database, as usual. What this means is that if the cache is still available (for example trying to fetch the same data on the same page load) it will use the cache, otherwise it will fetch it from the database.
  • If you have persistent cache then Transients are ONLY stored in the Object Cache and not in the database at all.

css.php