Transient
A transient is a piece of temporary data stored together with an expiration time, so that the result of a costly operation can be reused for a while instead of being recomputed on every request. The term is especially common in the WordPress ecosystem, where the Transients API provides a simple way to cache data with a built-in lifetime.
How transients work
A transient stores a value under a name, along with how long it should remain valid. When code needs that value, it first checks whether a non-expired transient exists. If it does, the stored value is returned immediately, skipping the expensive work. If the transient is missing or has expired, the code performs the operation, saves the fresh result as a new transient, and returns it. This is a straightforward form of caching, where the expiry time plays a role similar to a TTL on other cached data.
What transients are used for
Transients are ideal for data that is expensive to produce but does not need to be perfectly up to date every second — the result of a slow database query, a computed list, or a response fetched from an external API. Caching such results as transients can dramatically reduce load and speed up pages, because most visitors are served the stored value rather than triggering the full operation. The key design decision is the expiry: too long and users see stale data, too short and the cache rarely helps. Depending on the platform, transients may be kept in the database or in a fast in-memory store, which affects performance. Used well, transients are a lightweight, effective tool for smoothing out the cost of repeated expensive work without introducing a heavy caching infrastructure.
Powiązane pojęcia
Najczęstsze pytania
What happens when a transient expires?
Once its lifetime passes, the transient is treated as gone and the next request regenerates the underlying data and stores a fresh copy. This keeps cached values from becoming permanently stale.
