WP transients are a scheme to cache content for sharing across one or more WP sites for some specified period of time. Expiration dates or time frames are optional. Transients then can form a content state sharing mechanism that can extend across multiple sites within the domain of a single multi-site framework. Content which can have decay and expiration after a period of time, or content which can be constant, or form a scheme for dynamic constant, which may have some dynamism within an otherwise static frame. A highly useful feature for model driven development patterns. There are three WP functions used to operate on transient data:
- Establish the transient data and the associated time frame for retention.
- Obtain the transient data if it exists, else return false.
- Delete the transient data if it exists.
Two sets of the three transient functions are identified above. The site versions of the functions are designed for WP multiple site operations and are effectively the same as the other functions, with the following caveats:
- they work network wide when using WP Multisite
- the transient name should be 167 characters or less in length rather than the 191 characters otherwise allowed, although 172 is also noted as a limitation due to WP appending prefix data to the transient name to generate keys when storing data in the database. Short, unique names are good.
- while set_transient() sets transients that have an expiration time to not autoload, all transients added with `set_site_transient` will auto-load at all times. Autoload of all transients on all pages, needed or not, can create performance concerns if the items are not needed.
Transients can be used as a scheme for general sharing of text, arrays, and objects. WP provides serialization support and SQL escaping. Transients can also be used to cache results of queries which might occur with high frequency concerning result sets which change slowly. Annual results will only change when new annual data is incorporated into the query data. Until then, the same answer can be expected. Results for some queries used on routine dashboards can be cached and re-used to lower the load on servers, reduce operational expense, and speed results.