mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Added cache locker
This commit is contained in:
parent
723e0afa4e
commit
ebce312d1a
2 changed files with 58 additions and 5 deletions
|
|
@ -65,6 +65,36 @@ class CacheClient
|
||||||
return $this->Set($sKey.'/TIMER', time());
|
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 $sKey
|
||||||
* @param string $bClearAfterGet = false
|
* @param string $bClearAfterGet = false
|
||||||
|
|
|
||||||
|
|
@ -2666,18 +2666,36 @@ class Actions
|
||||||
$sValue = '';
|
$sValue = '';
|
||||||
if (!$sForce)
|
if (!$sForce)
|
||||||
{
|
{
|
||||||
$iTime = $oCacher->GetTimer($bLongCache ? $sDomainLongKeyValue : $sDomainKeyValue);
|
if ($bLongCache)
|
||||||
if (0 < $iTime && \time() < $iTime + (60 * ($bLongCache ? 60 * 24 : 1)) * ($bLongCache ? $iLongCacheTimeInDays : $iFastCacheTimeInMin))
|
|
||||||
{
|
{
|
||||||
$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 (0 === \strlen($sValue))
|
||||||
{
|
{
|
||||||
if ($bLongCache && !$oCacher->SetTimer($sDomainLongKeyValue))
|
if ($bLongCache)
|
||||||
{
|
{
|
||||||
return 'NO';
|
if (!$oCacher->SetTimer($sDomainLongKeyValue))
|
||||||
|
{
|
||||||
|
return 'NO';
|
||||||
|
}
|
||||||
|
|
||||||
|
$oCacher->SetLock($sDomainLongKeyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
$iCode = 0;
|
$iCode = 0;
|
||||||
|
|
@ -2698,6 +2716,11 @@ class Actions
|
||||||
|
|
||||||
$oCacher->Set($sDomainKeyValue, $sValue);
|
$oCacher->Set($sDomainKeyValue, $sValue);
|
||||||
$oCacher->Set($sDomainLongKeyValue, $sValue);
|
$oCacher->Set($sDomainLongKeyValue, $sValue);
|
||||||
|
|
||||||
|
if ($bLongCache)
|
||||||
|
{
|
||||||
|
$oCacher->RemoveLock($sDomainLongKeyValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sValue;
|
return $sValue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue