mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
32 lines
No EOL
763 B
PHP
32 lines
No EOL
763 B
PHP
<?php
|
|
|
|
class CurlWithCache extends Curl
|
|
{
|
|
const DEFAULT_CACHE = 600000;
|
|
|
|
public static function doCurl($method, $url, $params = [], $options = [])
|
|
{
|
|
$useCache = ($options['cache'] ?? true) && Apc::isEnabled();
|
|
$cacheTimeout = is_numeric($options['cache'] ?? null) ? $options['cache'] : static::DEFAULT_CACHE;
|
|
unset($options['cache']);
|
|
|
|
if ($useCache)
|
|
{
|
|
$cacheKey = md5('x' . $url . $method . serialize($options) . serialize($params));
|
|
$cachedData = apc_fetch($cacheKey);
|
|
if ($cachedData)
|
|
{
|
|
return $cachedData;
|
|
}
|
|
}
|
|
|
|
$response = parent::doCurl($method, $url, $params, $options);
|
|
|
|
if ($useCache)
|
|
{
|
|
apc_store($cacheKey, $response, $cacheTimeout);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
} |