Using the WordPress transients API
Your website’s speed matters a lot, because when your site is slow, your visitors will quickly go away and look for a competitors site that doesn’t waste their time. But computers are fast. Very fast. Yet, there are operations that are computationally intensive, network latency that increases access times, or complex database queries that can bring a even a powerful server to its knees. In such cases, a level of caching should be implemented where possible, so that a stored, pre-computed result is served to your visitors. When will this cache get refreshed is a matter of use-case, but as a general rule of thumb, it should be updated as rarely as possible. WordPress provides us with two distinct but similar APIs that help us implement caching. One one hand there’s the Cache API that provides us with a set of straightforward CRUD functions to easily implement caching, but doesn’t offer persistence out of the box. On the other hand, there is the Transients API, a set of functions that utilizes the Cache API under the hood (so, it’s a super-set) but also provides persistence out of the box. The latter is the one we’re going to investigate in this tutorial.
Source: https://managewp.org/articles/16654/using-the-wordpress-transients-api
source https://williechiu40.wordpress.com/2017/11/20/using-the-wordpress-transients-api/