I'm building a web with laravel that relies on an external API to get the data that I show to my users (http://eztvapi.re in my case). I'm using guzzle for the api calls and it works fine.
The API is very simple, it either displays a list of shows (with metadata for them) or the info of one show given its ID.
The problem comes when I need to show the info for, say, 15 given shows that a user has selected as favorite. That means I need to query the API 15 times, one for each shows, and that slows the web a lot (also it's too many requests for the API, that doesn't seem right to me).
Basically this:
foreach ($favorites as $fav) {
$client = new Client();
$res = $client->get('http://eztvapi.re/show/'.$fav->id);
$show = $res->json();
}
I've considered copying to my database the contents of the api, but that defeats the purpose of connecting to the api altogether, and it would need to be updated very frequently. I thought maybe cache was the way to go but I'm not clear on how to approach that route, I searched for laravel cache and it seems it's only aimed to cache queries to the database (or maybe I didn't understand well the docs).
What would be the proper way for this?