]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add an array implementation of cache and use it if we are not debugging
authorJoas Schilling <nickvergessen@gmx.de>
Mon, 12 Jan 2015 12:48:07 +0000 (13:48 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Mon, 16 Feb 2015 13:55:50 +0000 (14:55 +0100)
lib/private/memcache/arraycache.php [new file with mode: 0644]
lib/private/memcache/factory.php
tests/lib/memcache/arraycache.php [new file with mode: 0644]

diff --git a/lib/private/memcache/arraycache.php b/lib/private/memcache/arraycache.php
new file mode 100644 (file)
index 0000000..9456c0f
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Memcache;
+
+class ArrayCache extends Cache {
+       /** @var array Array with the cached data */
+       protected $cachedData = array();
+
+       /**
+        * {@inheritDoc}
+        */
+       public function get($key) {
+               if ($this->hasKey($key)) {
+                       return $this->cachedData[$key];
+               }
+               return null;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function set($key, $value, $ttl = 0) {
+               $this->cachedData[$key] = $value;
+               return true;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function hasKey($key) {
+               return isset($this->cachedData[$key]);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function remove($key) {
+               unset($this->cachedData[$key]);
+               return true;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function clear($prefix = '') {
+               if ($prefix === '') {
+                       $this->cachedData = [];
+                       return true;
+               }
+
+               foreach ($this->cachedData as $key => $value) {
+                       if (strpos($key, $prefix) === 0) {
+                               $this->remove($key);
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       static public function isAvailable() {
+               return true;
+       }
+}
index 1e663eecfe1bdf0a18a46f0f9ca032da0316a011..e8a91c522691a81df70e2d71167ff42b0b2fbdf3 100644 (file)
@@ -42,7 +42,7 @@ class Factory implements ICacheFactory {
                } elseif (Memcached::isAvailable()) {
                        return new Memcached($prefix);
                } else {
-                       return new Null($prefix);
+                       return new ArrayCache($prefix);
                }
        }
 
diff --git a/tests/lib/memcache/arraycache.php b/tests/lib/memcache/arraycache.php
new file mode 100644 (file)
index 0000000..1db673d
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * Copyright (c) 2015 Joas Schilling <nickvergessen@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 ArrayCache extends Cache {
+       protected function setUp() {
+               parent::setUp();
+               $this->instance = new \OC\Memcache\ArrayCache('');
+       }
+}