use trait for cas polyfill for xcache

This commit is contained in:
Robin Appelman 2015-04-30 13:39:31 +02:00
parent 96f9573a4b
commit a40a237441
1 changed files with 2 additions and 24 deletions

View File

@ -32,6 +32,8 @@ use OCP\IMemcache;
* functions etc.
*/
class XCache extends Cache implements IMemcache {
use CASTrait;
/**
* entries in XCache gets namespaced to prevent collisions between ownCloud instances and users
*/
@ -107,30 +109,6 @@ class XCache extends Cache implements IMemcache {
return xcache_dec($this->getPrefix() . $key, $step);
}
/**
* Compare and set
*
* @param string $key
* @param mixed $old
* @param mixed $new
* @return bool
*/
public function cas($key, $old, $new) {
//no native cas, emulate with locking
if ($this->add($key . '_lock', true)) {
if ($this->get($key) === $old) {
$this->set($key, $new);
$this->remove($key . '_lock');
return true;
} else {
$this->remove($key . '_lock');
return false;
}
} else {
return false;
}
}
static public function isAvailable() {
if (!extension_loaded('xcache')) {
return false;