Terme informatique

WordPress transient

A transient temporarily stores a cached data in WordPress.

View my favorites

Simple definition

A WordPress transient temporarily stores cached data with a maximum expiration time.

Technical definition

The Transients API stores a named value using functions such as set_transient() and get_transient(). The value can be stored in the database or handled by a persistent object cache. The expiration is a maximum lifetime: a transient can disappear earlier and code should be able to rebuild it.

What is it used for?

Avoid repeating an expensive calculation, database operation, or remote API request on every page load.

Practical example

A plugin caches the result of an external API request for ten minutes and refreshes it when the transient is missing.

Common issues

  • Code assumes the transient will always exist until its expiration
  • Stale data is not invalidated when the source changes
  • Persistent object cache behaves differently from database storage

Key takeaway: treat transient expiration as a maximum lifetime and always handle a cache miss.

♡ 0