All features

Cherry Blossom feature

Framework Traits: Transients trait

Caches callback results in per-site WordPress transients.

Caches callback results in per-site WordPress transients.

Capabilities and extension points

Gets a cached value or computes it when the transient is absent.

If the transient already exists, it will be returned. Else, it will be generated from the callback result. A stored false is indistinguishable from a cache miss and therefore causes regeneration.

  • param string $transient Transient name.
  • param int $expiration Lifetime in seconds; zero requests no expiration.
  • param callable $callable Callback producing the value to cache.
  • param array $args Optional callback arguments. Default empty array.
  • return mixed Transient value.

Computes a fresh value and replaces the transient.

  • param string $transient Transient name.
  • param int $expiration Lifetime in seconds; zero requests no expiration.
  • param callable $callable Callback producing the value to cache.
  • param array $args Optional callback arguments. Default empty array.
  • return mixed Transient value.

Source reference

This editable reference page is based on the PHP documentation in framework/traits/wordpress/trait-transients.php.