diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2015-01-12 13:48:07 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2015-02-16 14:55:50 +0100 |
commit | 8848b5f067f9b81f68508d2d739f0f951575e5e3 (patch) | |
tree | c055fa543378c999dd2f1f7496e784d258b6b293 /lib/private/memcache/arraycache.php | |
parent | 0d8b3afc32f15b1582bbf555796b9d112a91a4ef (diff) | |
download | nextcloud-server-8848b5f067f9b81f68508d2d739f0f951575e5e3.tar.gz nextcloud-server-8848b5f067f9b81f68508d2d739f0f951575e5e3.zip |
Add an array implementation of cache and use it if we are not debugging
Diffstat (limited to 'lib/private/memcache/arraycache.php')
-rw-r--r-- | lib/private/memcache/arraycache.php | 71 |
1 files changed, 71 insertions, 0 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; + } +} |