summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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.php13
-rw-r--r--lib/private/server.php13
-rw-r--r--lib/public/cachefactory.php26
-rw-r--r--lib/public/iservercontainer.php7
7 files changed, 68 insertions, 27 deletions
diff --git a/lib/private/memcache/apc.php b/lib/private/memcache/apc.php
index 575ee4427db..d5bc1498d65 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..48c97b59551 100644
--- a/lib/private/memcache/factory.php
+++ b/lib/private/memcache/factory.php
@@ -10,12 +10,25 @@ namespace OC\Memcache;
class Factory {
/**
+ * @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
*
* @param string $prefix
* @return \OC\Memcache\Cache
*/
function create($prefix = '') {
+ $prefix = $this->globalPrefix . '/' . $prefix;
if (XCache::isAvailable()) {
return new XCache($prefix);
} elseif (APCu::isAvailable()) {
diff --git a/lib/private/server.php b/lib/private/server.php
index 2cbd37a97d7..c9e593ec2ed 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -138,6 +138,10 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('UserCache', function($c) {
return new UserCache();
});
+ $this->registerService('MemCacheFactory', function ($c) {
+ $instanceId = \OC_Util::getInstanceId();
+ return new \OC\Memcache\Factory($instanceId);
+ });
$this->registerService('ActivityManager', function($c) {
return new ActivityManager();
});
@@ -298,6 +302,15 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
+ * Returns an \OCP\CacheFactory instance
+ *
+ * @return \OCP\CacheFactory
+ */
+ function getMemCacheFactory() {
+ return $this->query('MemCacheFactory');
+ }
+
+ /**
* Returns the current session
*
* @return \OCP\ISession
diff --git a/lib/public/cachefactory.php b/lib/public/cachefactory.php
new file mode 100644
index 00000000000..1bb0ea3dd51
--- /dev/null
+++ b/lib/public/cachefactory.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Copyright (c) 2014 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 OCP;
+
+interface CacheFactory{
+ /**
+ * Get a memory cache instance
+ *
+ * @param string $prefix
+ * @return $return \OCP\ICache
+ */
+ public function create($prefix = '');
+
+ /**
+ * Check if a memory cache backend is available
+ *
+ * @return bool
+ */
+ public function isAvailable();
+}
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index b958d2d03f4..67884bdc3e4 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -142,6 +142,13 @@ interface IServerContainer {
function getCache();
/**
+ * Returns an \OCP\CacheFactory instance
+ *
+ * @return \OCP\CacheFactory
+ */
+ function getMemCacheFactory();
+
+ /**
* Returns the current session
*
* @return \OCP\ISession