Cache simple/price response for 60 seconds

fixes 
This commit is contained in:
Ioannis 2025-02-13 07:46:01 +01:00
parent a34a2bb487
commit 20e41d40a0

View file

@ -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';