mirror of
https://github.com/rottenwheel/moner.ooo.git
synced 2025-03-26 00:58:45 +00:00
Merge pull request #14 from ilazaridis/feature/cache-currencies
Cache simple/price response for 60 seconds
This commit is contained in:
commit
46e7cfbdde
1 changed files with 8 additions and 1 deletions
|
@ -11,6 +11,13 @@ function fetchJson($filename) {
|
|||
return json_decode(file_get_contents($filename), true);
|
||||
}
|
||||
|
||||
function fetchCache(string $key, string $url)
|
||||
{
|
||||
return apcu_entry($key, function() use ($url) {
|
||||
return makeApiRequest($url);
|
||||
}, 60);
|
||||
}
|
||||
|
||||
// Make an API request and return the JSON response
|
||||
function makeApiRequest($url) {
|
||||
$ch = curl_init($url);
|
||||
|
@ -72,7 +79,7 @@ function fetchAvailableCurrencies() {
|
|||
// Fetch currency data from CoinGecko API
|
||||
function fetchCurrencyData($currencies) {
|
||||
$apiUrl = getCoinGeckoApiUrl('simple/price', ['ids' => 'monero', 'vs_currencies' => implode(',', array_map('strtolower', $currencies))]);
|
||||
return makeApiRequest($apiUrl);
|
||||
return fetchCache('currency_data', $apiUrl);
|
||||
}
|
||||
|
||||
$currencyFile = 'coingecko.json';
|
||||
|
|
Loading…
Reference in a new issue