Object Cache API

Caching can greatly improve WordPress performance by saving a copy of the static files generated dynamically from PHP and the data received from the database and serving them to visitors who request the same pages. This can be set to expire after a preset period of time or upon request. ⏱️

Object caching, page caching, and browser caching are some of the various types of caching that can be enabled on your site.

You can learn more about them from the below resources:

Transients

For an example of caching a remote request using transients, see the example in Interacting with remote data and APIs.

Let’s see an example of Object Cache. The code calls the function two times. The function tries to get data from the cache, and if the data is blank, then it saves data in the cache to return in the next call.