mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
improve cache invalidation for curl
This commit is contained in:
parent
0d5fd01e8f
commit
c6cf3f2a89
1 changed files with 14 additions and 5 deletions
|
@ -6,13 +6,15 @@ class CurlWithCache extends Curl
|
|||
|
||||
public static function doCurl($method, $url, $params = [], $options = [])
|
||||
{
|
||||
$useCache = ($options['cache'] ?? true) && Apc::isEnabled();
|
||||
$cacheAllowed = $options['cache'] ?? true;
|
||||
$cacheEnabled = Apc::isEnabled();
|
||||
|
||||
$cacheTimeout = is_numeric($options['cache'] ?? null) ? $options['cache'] : static::DEFAULT_CACHE;
|
||||
unset($options['cache']);
|
||||
|
||||
if ($useCache)
|
||||
$cacheKey = $cacheEnabled ? md5($url . $method . serialize($options) . serialize($params)) : null;
|
||||
if ($cacheAllowed && $cacheKey)
|
||||
{
|
||||
$cacheKey = md5('x' . $url . $method . serialize($options) . serialize($params));
|
||||
$cachedData = apc_fetch($cacheKey);
|
||||
if ($cachedData)
|
||||
{
|
||||
|
@ -22,9 +24,16 @@ class CurlWithCache extends Curl
|
|||
|
||||
$response = parent::doCurl($method, $url, $params, $options);
|
||||
|
||||
if ($useCache)
|
||||
if ($cacheEnabled)
|
||||
{
|
||||
apc_store($cacheKey, $response, $cacheTimeout);
|
||||
if ($cacheAllowed)
|
||||
{
|
||||
apc_store($cacheKey, $response, $cacheTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
apc_delete($cacheKey);
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
|
Loading…
Add table
Reference in a new issue