Added cache locker

This commit is contained in:
RainLoop Team 2014-11-18 15:47:25 +04:00
parent 723e0afa4e
commit ebce312d1a
2 changed files with 58 additions and 5 deletions

View file

@ -65,6 +65,36 @@ class CacheClient
return $this->Set($sKey.'/TIMER', time());
}
/**
* @param string $sKey
*
* @return bool
*/
public function SetLock($sKey)
{
return $this->Set($sKey.'/LOCK', '1');
}
/**
* @param string $sKey
*
* @return bool
*/
public function RemoveLock($sKey)
{
return $this->Set($sKey.'/LOCK', '0');
}
/**
* @param string $sKey
*
* @return bool
*/
public function GetLock($sKey)
{
return '1' === $this->Get($sKey.'/LOCK');
}
/**
* @param string $sKey
* @param string $bClearAfterGet = false

View file

@ -2666,18 +2666,36 @@ class Actions
$sValue = '';
if (!$sForce)
{
$iTime = $oCacher->GetTimer($bLongCache ? $sDomainLongKeyValue : $sDomainKeyValue);
if (0 < $iTime && \time() < $iTime + (60 * ($bLongCache ? 60 * 24 : 1)) * ($bLongCache ? $iLongCacheTimeInDays : $iFastCacheTimeInMin))
if ($bLongCache)
{
$sValue = $oCacher->Get($bLongCache ? $sDomainLongKeyValue : $sDomainKeyValue);
$bLock = $oCacher->GetLock($sDomainLongKeyValue);
$iTime = $bLock ? 0 : $oCacher->GetTimer($sDomainLongKeyValue);
if ($bLock || (0 < $iTime && \time() < $iTime + (60 * 60 * 24) * $iLongCacheTimeInDays))
{
$sValue = $oCacher->Get($sDomainLongKeyValue);
}
}
else
{
$iTime = $oCacher->GetTimer($sDomainKeyValue);
if (0 < $iTime && \time() < $iTime + 60 * $iFastCacheTimeInMin)
{
$sValue = $oCacher->Get($sDomainKeyValue);
}
}
}
if (0 === \strlen($sValue))
{
if ($bLongCache && !$oCacher->SetTimer($sDomainLongKeyValue))
if ($bLongCache)
{
return 'NO';
if (!$oCacher->SetTimer($sDomainLongKeyValue))
{
return 'NO';
}
$oCacher->SetLock($sDomainLongKeyValue);
}
$iCode = 0;
@ -2698,6 +2716,11 @@ class Actions
$oCacher->Set($sDomainKeyValue, $sValue);
$oCacher->Set($sDomainLongKeyValue, $sValue);
if ($bLongCache)
{
$oCacher->RemoveLock($sDomainLongKeyValue);
}
}
return $sValue;