diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2015-02-16 15:35:20 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2015-02-16 15:35:20 +0100 |
commit | 8eb804b1f60befd6491a8b8a1ba29247bfc8c419 (patch) | |
tree | 79b2abe7ef783e3941a8e3ffe45e7f1d7e9253f4 | |
parent | 9c47ab91f2c27ced6b80ce44003809358da76ee2 (diff) | |
parent | 8848b5f067f9b81f68508d2d739f0f951575e5e3 (diff) | |
download | nextcloud-server-8eb804b1f60befd6491a8b8a1ba29247bfc8c419.tar.gz nextcloud-server-8eb804b1f60befd6491a8b8a1ba29247bfc8c419.zip |
Merge pull request #13269 from owncloud/issue/13211-cache-array-implementation
Add an array implementation of cache and use it if we are not debugging
-rw-r--r-- | lib/private/memcache/arraycache.php | 71 | ||||
-rw-r--r-- | lib/private/memcache/factory.php | 2 | ||||
-rw-r--r-- | tests/lib/memcache/arraycache.php | 17 |
3 files changed, 89 insertions, 1 deletions
diff --git a/lib/private/memcache/arraycache.php b/lib/private/memcache/arraycache.php new file mode 100644 index 00000000000..9456c0f80c6 --- /dev/null +++ b/lib/private/memcache/arraycache.php @@ -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; + } +} diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php index 1e663eecfe1..e8a91c52269 100644 --- a/lib/private/memcache/factory.php +++ b/lib/private/memcache/factory.php @@ -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 index 00000000000..1db673da2a8 --- /dev/null +++ b/tests/lib/memcache/arraycache.php @@ -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(''); + } +} |