summaryrefslogtreecommitdiffstats
path: root/lib/private/memcache
diff options
context:
space:
mode:
authoricewind1991 <robin@icewind.nl>2014-02-04 05:38:53 -0800
committericewind1991 <robin@icewind.nl>2014-02-04 05:38:53 -0800
commita27529709b3c666b89fa7e435c400f9937ee2efa (patch)
tree4749f7c85f2e305c1b39f7e224cc4bc786f28f25 /lib/private/memcache
parente266e50699c43b26b67701f0e33a081ee6978425 (diff)
parent1ab7ca0a19d5f3984e87f99945d81aecffbbae19 (diff)
downloadnextcloud-server-a27529709b3c666b89fa7e435c400f9937ee2efa.tar.gz
nextcloud-server-a27529709b3c666b89fa7e435c400f9937ee2efa.zip
Merge pull request #6647 from owncloud/memcache-public
Add Memcache to the public api
Diffstat (limited to 'lib/private/memcache')
-rw-r--r--lib/private/memcache/apc.php27
-rw-r--r--lib/private/memcache/apcu.php7
-rw-r--r--lib/private/memcache/cache.php2
-rw-r--r--lib/private/memcache/factory.php17
4 files changed, 25 insertions, 28 deletions
diff --git a/lib/private/memcache/apc.php b/lib/private/memcache/apc.php
index e995cbc526e..332bbfead00 100644
--- a/lib/private/memcache/apc.php
+++ b/lib/private/memcache/apc.php
@@ -9,15 +9,8 @@
namespace OC\Memcache;
class APC extends Cache {
- /**
- * entries in APC gets namespaced to prevent collisions between owncloud instances and users
- */
- protected function getNameSpace() {
- return $this->prefix;
- }
-
public function get($key) {
- $result = apc_fetch($this->getNamespace() . $key, $success);
+ $result = apc_fetch($this->getPrefix() . $key, $success);
if (!$success) {
return null;
}
@@ -25,26 +18,22 @@ class APC extends Cache {
}
public function set($key, $value, $ttl = 0) {
- return apc_store($this->getNamespace() . $key, $value, $ttl);
+ return apc_store($this->getPrefix() . $key, $value, $ttl);
}
public function hasKey($key) {
- return apc_exists($this->getNamespace() . $key);
+ return apc_exists($this->getPrefix() . $key);
}
public function remove($key) {
- return apc_delete($this->getNamespace() . $key);
+ return apc_delete($this->getPrefix() . $key);
}
public function clear($prefix = '') {
- $ns = $this->getNamespace() . $prefix;
- $cache = apc_cache_info('user');
- foreach ($cache['cache_list'] as $entry) {
- if (strpos($entry['info'], $ns) === 0) {
- apc_delete($entry['info']);
- }
- }
- return true;
+ $ns = $this->getPrefix() . $prefix;
+ $ns = preg_quote($ns, '/');
+ $iter = new \APCIterator('user', '/^' . $ns . '/');
+ return apc_delete($iter);
}
static public function isAvailable() {
diff --git a/lib/private/memcache/apcu.php b/lib/private/memcache/apcu.php
index dac0f5f208a..7f780f32718 100644
--- a/lib/private/memcache/apcu.php
+++ b/lib/private/memcache/apcu.php
@@ -9,13 +9,6 @@
namespace OC\Memcache;
class APCu extends APC {
- public function clear($prefix = '') {
- $ns = $this->getNamespace() . $prefix;
- $ns = preg_quote($ns, '/');
- $iter = new \APCIterator('user', '/^'.$ns.'/');
- return apc_delete($iter);
- }
-
static public function isAvailable() {
if (!extension_loaded('apcu')) {
return false;
diff --git a/lib/private/memcache/cache.php b/lib/private/memcache/cache.php
index 0ad1cc7ec03..03671b3f240 100644
--- a/lib/private/memcache/cache.php
+++ b/lib/private/memcache/cache.php
@@ -18,7 +18,7 @@ abstract class Cache implements \ArrayAccess {
* @param string $prefix
*/
public function __construct($prefix = '') {
- $this->prefix = \OC_Util::getInstanceId() . '/' . $prefix;
+ $this->prefix = $prefix;
}
public function getPrefix() {
diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php
index fde7d947567..334cf9a1f0e 100644
--- a/lib/private/memcache/factory.php
+++ b/lib/private/memcache/factory.php
@@ -8,7 +8,21 @@
namespace OC\Memcache;
-class Factory {
+use \OCP\ICacheFactory;
+
+class Factory implements ICacheFactory {
+ /**
+ * @var string $globalPrefix
+ */
+ private $globalPrefix;
+
+ /**
+ * @param string $globalPrefix
+ */
+ public function __construct($globalPrefix) {
+ $this->globalPrefix = $globalPrefix;
+ }
+
/**
* get a cache instance, will return null if no backend is available
*
@@ -16,6 +30,7 @@ class Factory {
* @return \OC\Memcache\Cache
*/
function create($prefix = '') {
+ $prefix = $this->globalPrefix . '/' . $prefix;
if (XCache::isAvailable()) {
return new XCache($prefix);
} elseif (APCu::isAvailable()) {