Unverified Commit d0107b17 authored by damiankloip's avatar damiankloip Committed by damiankloip
Browse files

Issue #2997186 by damiankloip, Fabianx: Remove key() usage from Lock Backend

parent 9b92d624
......@@ -60,11 +60,10 @@ class MemcacheLockBackend extends LockBackendAbstract {
$timeout = (int) max($timeout, 1);
$lock_id = $this->getLockId();
$key = $this->getKey($name);
if (isset($this->locks[$name])) {
// Try to extend the expiration of a lock we already acquired.
$success = !$this->lockMayBeAvailable($name) && $this->memcache->set($key, $lock_id, $timeout);
$success = !$this->lockMayBeAvailable($name) && $this->memcache->set($name, $lock_id, $timeout);
if (!$success) {
// The lock was broken.
......@@ -75,7 +74,7 @@ class MemcacheLockBackend extends LockBackendAbstract {
}
else {
if ($this->lockMayBeAvailable($name)) {
$success = $this->memcache->add($key, $lock_id, $timeout);
$success = $this->memcache->add($name, $lock_id, $timeout);
if (!$success) {
return FALSE;
......@@ -96,14 +95,14 @@ class MemcacheLockBackend extends LockBackendAbstract {
* {@inheritdoc}
*/
public function lockMayBeAvailable($name) {
return !$this->memcache->get($this->getKey($name));
return !$this->memcache->get($name);
}
/**
* {@inheritdoc}
*/
public function release($name) {
$this->memcache->delete($this->getKey($name));
$this->memcache->delete($name);
// We unset unconditionally since caller assumes lock is released anyway.
unset($this->locks[$name]);
}
......@@ -117,26 +116,14 @@ class MemcacheLockBackend extends LockBackendAbstract {
}
foreach ($this->locks as $name => $id) {
$key = $this->getKey($name);
$value = $this->memcache->get($key);
$value = $this->memcache->get($name);
if ($value == $lock_id) {
$this->memcache->delete($key);
$this->memcache->delete($name);
}
}
$this->locks = [];
}
/**
* Gets a storage key based on the lock name.
*
* @param string $name
*
* @return string
*/
protected function getKey($name) {
return sprintf('lock:%s:%s', $this->bin, $name);
}
}
<?php
/**
* @file
* Contains \Drupal\memcache\Tests\MemcacheLockFunctionalTest.
*/
namespace Drupal\memcache\Tests;
use Drupal\Tests\system\Functional\Lock\LockFunctionalTest;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment