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
- very time consuming queries.
- 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
- Each Transient has name
- when you need data, check to see if it exists (in transient).
- if it does use it.
- 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.