Transients

Transient is kind of cacheing. Transient word means “it lasts for a very short period of time.”

Bit of data is cached for intermittent amount of time. intermittent because we can not decide how much time data will be cached. there are many many reasons that could destroy transient.

use cases for transient

  1. very time consuming queries.
  2. for http requests. for example if scripts make api request on every page load then we want to cache that and use transient for that purpose.

How to do transient work

  1. Each Transient has name
  2. when you need data, check to see if it exists (in transient).
  3. if it does use it.
  4. if it does generate the data and set it for the next time.

Where are transient stored

  • First wordpress looks for system level caching module like mamcached, Redis, Varnish etc. These are very very fast and much prefered. Failing that transients are stored in wordpress options table. Yes, this is still a database call but simple, speedy one. you don’t have to do anything to set this up , wordpress magically handles it.

How is the magic acomplished

  • wordpress provides fucntion to set, get and delete transients. Setting that already exists updates it.
  • Using these function you simply ask for the data you want, if its not these you build it and store it for the next time.