Unverified Commit 6086e151 authored by damiankloip's avatar damiankloip Committed by damiankloip
Browse files

Issue #2905341 by damiankloip, Fabianx, Evgeny_Yudkin: MemcacheLockBackend...

Issue #2905341 by damiankloip, Fabianx, Evgeny_Yudkin: MemcacheLockBackend service should use "add" and "delete" instead of "get" and "set"
parent 9ea21dba
......@@ -84,6 +84,22 @@ class DrupalMemcache extends DrupalMemcacheBase {
return $result;
}
/**
* {@inheritdoc}
*/
public function add($key, $value, $expire = 0) {
$collect_stats = $this->stats_init();
$full_key = $this->key($key);
$result = $this->memcache->add($full_key, $value,false, $expire);
if ($collect_stats) {
$this->stats_write('add', 'cache', [$full_key => (int)$result]);
}
return $result;
}
/**
* {@inheritdoc}
*/
......
......@@ -68,6 +68,21 @@ interface DrupalMemcacheInterface {
*/
public function delete($key);
/**
* Add an item to Memcache if it doesn't exist already.
*
* @param string $key
* The key to add.
* @param mixed $value
* The value to add.
* @param int $expire
* The expiration time in seconds.
*
* @return bool
* TRUE on success or FALSE on failure.
*/
public function add($key, $value, $expire = 0);
/**
* Prepares the memcache key.
*
......
......@@ -81,6 +81,22 @@ class DrupalMemcached extends DrupalMemcacheBase {
return $result;
}
/**
* {@inheritdoc}
*/
public function add($key, $value, $expire = 0) {
$collect_stats = $this->stats_init();
$full_key = $this->key($key);
$result = $this->memcache->add($full_key, $value, $expire);
if ($collect_stats) {
$this->stats_write('add', 'cache', [$full_key => (int)$result]);
}
return $result;
}
/**
* {@inheritdoc}
*/
......
......@@ -38,6 +38,9 @@ class MemcacheLockBackend extends LockBackendAbstract {
/**
* Constructs a new MemcacheLockBackend.
*
* @param string $bin
* @param \Drupal\memcache\DrupalMemcacheInterface $memcache
*/
public function __construct($bin, DrupalMemcacheInterface $memcache) {
$this->bin = $bin;
......@@ -72,7 +75,7 @@ class MemcacheLockBackend extends LockBackendAbstract {
}
else {
if ($this->lockMayBeAvailable($name)) {
$success = $this->memcache->set($key, $lock_id, $timeout);
$success = $this->memcache->add($key, $lock_id, $timeout);
if (!$success) {
return FALSE;
......@@ -127,9 +130,13 @@ class MemcacheLockBackend extends LockBackendAbstract {
/**
* Gets a storage key based on the lock name.
*
* @param string $name
*
* @return string
*/
protected function getKey($name) {
return 'lock:' . $this->bin . ':' . $name;
return sprintf('lock:%s:%s', $this->bin, $name);
}
}
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