]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add ACPu memory cache
authorBart Visscher <bartv@thisnet.nl>
Wed, 24 Jul 2013 19:50:15 +0000 (21:50 +0200)
committerBart Visscher <bartv@thisnet.nl>
Wed, 24 Jul 2013 19:50:15 +0000 (21:50 +0200)
lib/memcache/apcu.php [new file with mode: 0644]
lib/memcache/factory.php
tests/lib/memcache/apc.php
tests/lib/memcache/apcu.php [new file with mode: 0644]

diff --git a/lib/memcache/apcu.php b/lib/memcache/apcu.php
new file mode 100644 (file)
index 0000000..ccc1aa6
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Memcache;
+
+class APCu extends APC {
+       public function clear($prefix = '') {
+               $ns = $this->getNamespace() . $prefix;
+               $ns = preg_quote($ns, '/');
+               $iter = new \APCIterator('/^'.$ns.'/');
+               return apc_delete($iter);
+       }
+
+       static public function isAvailable() {
+               if (!extension_loaded('apcu')) {
+                       return false;
+               } elseif (!ini_get('apc.enable_cli') && \OC::$CLI) {
+                       return false;
+               } else {
+                       return true;
+               }
+       }
+}
index b1b49971031f2063e0f9f3d431c2925bb841782f..4c1b1ab207f228cbb5bb7a1774d2820733b0c6ad 100644 (file)
@@ -18,6 +18,8 @@ class Factory {
        function create($prefix = '') {
                if (XCache::isAvailable()) {
                        return new XCache($prefix);
+               } elseif (APCu::isAvailable()) {
+                       return new APCu($prefix);
                } elseif (APC::isAvailable()) {
                        return new APC($prefix);
                } elseif (Memcached::isAvailable()) {
@@ -33,6 +35,6 @@ class Factory {
         * @return bool
         */
        public function isAvailable() {
-               return XCache::isAvailable() || APC::isAvailable() || Memcached::isAvailable();
+               return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable() || Memcached::isAvailable();
        }
 }
index 6b2a49470ba21d7391ae6920c2f83e33ff27222a..e5d753a4fa5e27381651fd1643238bc0eaacadd4 100644 (file)
@@ -15,6 +15,10 @@ class APC extends Cache {
                        $this->markTestSkipped('The apc extension is not available.');
                        return;
                }
+               if(\OC\Memcache\APCu::isAvailable()) {
+                       $this->markTestSkipped('The apc extension is emulated by ACPu.');
+                       return;
+               }
                $this->instance=new \OC\Memcache\APC(uniqid());
        }
 }
diff --git a/tests/lib/memcache/apcu.php b/tests/lib/memcache/apcu.php
new file mode 100644 (file)
index 0000000..7b99e7c
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Memcache;
+
+class APCu extends Cache {
+       public function setUp() {
+               if(!\OC\Memcache\APCu::isAvailable()) {
+                       $this->markTestSkipped('The APCu extension is not available.');
+                       return;
+               }
+               $this->instance=new \OC\Memcache\APCu(uniqid());
+       }
+}