summaryrefslogtreecommitdiffstats
path: root/lib/private/memcache/xcache.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2015-04-29 16:34:36 +0200
committerRobin Appelman <icewind@owncloud.com>2015-04-30 14:48:39 +0200
commitacf30ede95f4b8986787f81edcf025a84237b7c5 (patch)
tree8bfd36e370c084793f98a6cf0366916ab27f66cb /lib/private/memcache/xcache.php
parent29213b6136a4b2f71e5f981e9bc08e3e76128d4e (diff)
downloadnextcloud-server-acf30ede95f4b8986787f81edcf025a84237b7c5.tar.gz
nextcloud-server-acf30ede95f4b8986787f81edcf025a84237b7c5.zip
add compare and swap to memcache
Diffstat (limited to 'lib/private/memcache/xcache.php')
-rw-r--r--lib/private/memcache/xcache.php28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/private/memcache/xcache.php b/lib/private/memcache/xcache.php
index 48b0bd8a289..3a5bd73d8ad 100644
--- a/lib/private/memcache/xcache.php
+++ b/lib/private/memcache/xcache.php
@@ -24,6 +24,7 @@
*/
namespace OC\Memcache;
+
use OCP\IMemcache;
/**
@@ -92,7 +93,6 @@ class XCache extends Cache implements IMemcache {
* @return int | bool
*/
public function inc($key, $step = 1) {
- $this->add($key, 0);
return xcache_inc($this->getPrefix() . $key, $step);
}
@@ -107,11 +107,35 @@ 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;
}
- if (\OC::$CLI) {
+ if (\OC::$CLI && !getenv('XCACHE_TEST')) {
return false;
}
if (!function_exists('xcache_unset_by_prefix') && ini_get('xcache.admin.enable_auth')) {