Skip to content

Commit

Permalink
Unification lock method in cache handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Feb 23, 2017
1 parent cd8ae42 commit 635fd22
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
8 changes: 3 additions & 5 deletions libraries/joomla/cache/storage/apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,9 @@ public static function isSupported()
*/
public function lock($id, $group, $locktime)
{
$returning = new stdClass;
$returning->locklooped = false;
$returning = (object) array('locklooped' => false);

$looptime = $locktime * 10;

$cache_id = $this->_getCacheId($id, $group) . '_lock';

$data_lock = apc_add($cache_id, 1, $locktime);
Expand All @@ -271,15 +269,15 @@ public function lock($id, $group, $locktime)
{
if ($lock_counter > $looptime)
{
$returning->locked = false;
$returning->locklooped = true;
break;
}

usleep(100);
$data_lock = apc_add($cache_id, 1, $locktime);
$lock_counter++;
}

$returning->locklooped = true;
}

$returning->locked = $data_lock;
Expand Down
8 changes: 3 additions & 5 deletions libraries/joomla/cache/storage/apcu.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,9 @@ public static function isSupported()
*/
public function lock($id, $group, $locktime)
{
$returning = new stdClass;
$returning->locklooped = false;
$returning = (object) array('locklooped' => false);

$looptime = $locktime * 10;

$cache_id = $this->_getCacheId($id, $group) . '_lock';

$data_lock = apcu_add($cache_id, 1, $locktime);
Expand All @@ -282,15 +280,15 @@ public function lock($id, $group, $locktime)
{
if ($lock_counter > $looptime)
{
$returning->locked = false;
$returning->locklooped = true;
break;
}

usleep(100);
$data_lock = apcu_add($cache_id, 1, $locktime);
$lock_counter++;
}

$returning->locklooped = true;
}

$returning->locked = $data_lock;
Expand Down
3 changes: 1 addition & 2 deletions libraries/joomla/cache/storage/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ public static function isSupported()
*/
public function lock($id, $group, $locktime)
{
$returning = new stdClass;
$returning->locklooped = false;
$returning = (object) array('locklooped' => false);

$looptime = $locktime * 10;
$path = $this->_getFilePath($id, $group);
Expand Down
4 changes: 1 addition & 3 deletions libraries/joomla/cache/storage/memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,9 @@ public static function isSupported()
*/
public function lock($id, $group, $locktime)
{
$returning = new stdClass;
$returning->locklooped = false;
$returning = (object) array('locklooped' => false);

$looptime = $locktime * 10;

$cache_id = $this->_getCacheId($id, $group);

$data_lock = static::$_db->add($cache_id . '_lock', 1, 0, $locktime);
Expand Down
4 changes: 1 addition & 3 deletions libraries/joomla/cache/storage/memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,9 @@ public static function isSupported()
*/
public function lock($id, $group, $locktime)
{
$returning = new stdClass;
$returning->locklooped = false;
$returning = (object) array('locklooped' => false);

$looptime = $locktime * 10;

$cache_id = $this->_getCacheId($id, $group);

$data_lock = static::$_db->add($cache_id . '_lock', 1, $locktime);
Expand Down

0 comments on commit 635fd22

Please sign in to comment.