WordPress REST API in the Wild: Cache Clearing – Shawn Hooper – WordPress Developer & Speaker


In the last few weeks, I’ve been doing a lot of work integrating & automating some of the systems we use at Actionable.co. This week, I found an interesting use for the WordPress REST API that I thought I’d share. We have a web page on one of our public sites that shows the names, locations and headshots of our consultant network. This data does not originate in WordPress, but in a separate platform. I make a REST call to that platform to retrieve the most up-to-date information to display on this page. For reasons of performance, I cache this data. Until this week, I had instructed WordPress to keep this data for 24 hours.
Here’s a snippet of that code (originated in a class, which is why you’ll see $this used.
1
2
3
4
5
6
7
8
9
10
11
12
// Retrieve Consultant List from Cache
$this->consultantJsonData = wp_cache_get( ‘active_consultant_list’, ‘gem_acp_network_data’ );
 
// If no cached version exists, retrieve consultant list from the
// Conversations API, and then cache it for future use.
if ( $this->consultantJsonData === false ) {
$response = wp_remote_get( ‘https://example.com/api/Consultants/consultantList&8217; );
if ( is_array( $response
Source: https://managewp.org/articles/14322/wordpress-rest-api-in-the-wild-cache-clearing-shawn-hooper-wordpress-developer-speaker




source https://williechiu40.wordpress.com/2017/02/03/wordpress-rest-api-in-the-wild-cache-clearing-shawn-hooper-wordpress-developer-speaker/