From ebce312d1a531ba0615e99b9f9cdb5215351a329 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Tue, 18 Nov 2014 15:47:25 +0400 Subject: [PATCH] Added cache locker --- .../libraries/MailSo/Cache/CacheClient.php | 30 +++++++++++++++++ rainloop/v/0.0.0/app/src/RainLoop/Actions.php | 33 ++++++++++++++++--- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Cache/CacheClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Cache/CacheClient.php index 24cb91519..3073dbf1f 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Cache/CacheClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Cache/CacheClient.php @@ -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 diff --git a/rainloop/v/0.0.0/app/src/RainLoop/Actions.php b/rainloop/v/0.0.0/app/src/RainLoop/Actions.php index 2ffb6ef40..eefaab605 100644 --- a/rainloop/v/0.0.0/app/src/RainLoop/Actions.php +++ b/rainloop/v/0.0.0/app/src/RainLoop/Actions.php @@ -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;