How to cache a custom API call?

I build a little Python API and would like to cache the responses for 24-hrs.

As I use it in a shortcode like [google keyword=example] it will always do the API-call once I open the specific Wordpress site.

I use the shortcode more than once, so the pagespeed is kinda slow. There is also a problem with too many requests on the API which I want to prevent by the caching Or is there another workaround?

Is there an easy way to cache my PHP-curl?

The code is basically only a curl post-request to my Python API.

I am also open for Plugins like fastest-cache, I just need an easy solution. My PHP knowledge is not really good.

Thank you for your ideas and help!

EDIT // little snipped of what the function does

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL = '***',
  CURLOPT_RETURNTRANSFER = true,
  CURLOPT_ENCODING = '',
  CURLOPT_MAXREDIRS = 10,
  CURLOPT_TIMEOUT = 0,
  CURLOPT_FOLLOWLOCATION = true,
  CURLOPT_HTTP_VERSION = CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST = 'POST',
  CURLOPT_POSTFIELDS ='{keyword : '. $atts['keyword'] .' }',
  CURLOPT_HTTPHEADER = array(
    'Content-Type: application/json'
  ),
));
$response = curl_exec($curl);
$data = json_decode($response);

curl_close($curl);
return $data-result; 
}

Topic plugin-wp-supercache rest-api shortcode cache Wordpress performance

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.