Merge pull request from ilazaridis/feature/cache-currencies

Cache simple/price response for 60 seconds
This commit is contained in:
rottenwheel 2025-02-13 11:38:23 +00:00 committed by GitHub
commit 46e7cfbdde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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