1

I'm using PHP last.fm API to fetch artist image

I'd like to know how to cache the calls so that I don't need to make same call again and again. The API has facility to cache : DiskCache, SqliteCache but there is no documentation, could anyone please shed some light on it?

Below is my code :

<?php
require __DIR__ . "/src/lastfm.api.php";

// set api key
CallerFactory::getDefaultCaller()->setApiKey(LAST_FM_API_KEY);

// search for the Coldplay band
$artistName = "Coldplay";
$limit = 1;
$results = Artist::search($artistName, $limit);

echo "<ul>";
while ($artist = $results->current()) {
    echo "<li><div>";
    echo "Artist URL: " . $artist->getUrl() . "<br>";
    echo '<img src="' . $artist->getImage(4) . '">';
    echo "</div></li>";

    $artist = $results->next();
}
echo "</ul>";

?>
4

0 回答 0