Optimizing plugin performance by storing external data using transients
Some WordPress functions, such as the fetch_feed
function that we saw in the Displaying RSS items from an external feed recipe, offer a built-in caching mechanism. This is not the case when building custom code to retrieve information from other online data sources. The following recipe takes a look at using the public API of a transportation agency, Bay Area Rapid Transit, in the San Francisco area. It shows how to retrieve and cache remote XML data in our local site database using transients to speed up site performance while also alleviating the load on the remote data source.
Getting ready
You should have access to a WordPress development environment.
How to do it...
Follow these steps to query, cache, and display transit data from an external source:
- Navigate to the WordPress
plugins
directory of your development installation. - Create a new directory called
ch11-transit-feed
. - Navigate...