Alisa Herr

my picture
  • NC native
  • I love food
  • Lead Web Developer at Cuberis
  • Taught myself how to code in 1996
  • Started using WordPress in 2009

Get in touch!


About Transients and the API

What is a transient?

  • A piece of information that you need to access periodically, which is stored temporarily in a cache.

What is the Transients API?

  • Key-value pairs with expiration time
  • Value can be a string, array, or object
  • API handles serialization automatically

Why should I use it?

  • Server load optimization
  • Response time optimization

What can I use it for?

  • Long-running tasks / slow SQL queries
  • Fragment caching
  • Responses from requests of external APIs

What should I NOT use it for?

  • Single-use data storage
  • Anything you can't recreate when needed
  • Something you need to be in the database, guaranteed

How the Transients API works

The functions of the API

Saving a transient

        set_transient( $transient, $value, $expiration );

Retrieving a transient

        get_transient( $transient );

Deleting a transient

        delete_transient( $transient );

How transients are stored

  • Options table
  • Object cache

How expiration works

  • Expiration time = maximum age
  • Won't expire on their own
  • The function get_transient() checks if transient is old
    • If yes, it deletes it
    • If no, it returns it

How to use the Transients API

Live demo

  1. Getting some data from an external API without using a transient
  2. Getting the same data from a transient (without object caching)
  3. Getting the same data from a transient (with object caching)

Edit page »

Speed Comparisons

Without Transients APITransients API (default)Transients API (object caching)
Time (s)0.394720.000910.00025
Time (s)0.332020.000990.00026
Time (s)0.248120.001110.00022
Average (s)0.324950.001000.00024
Improvement--->300x faster>1300x faster

Get out there and use the
Transients API already!


Thank You!