aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-03-05 13:05:17 +0100
committerLukas Reschke <lukas@owncloud.com>2015-03-05 13:05:17 +0100
commit9f5433c0c3050c61e3e1cc2b7a71352dfe7f9250 (patch)
tree2a54120ae1d5f1a4dafa3f978634b44d532d24e7 /lib
parent7e0fd8fb501459f3ff1cfa5ddb40e1c97d50d617 (diff)
parent78819da3bf72eae29bc61170141f31a5e60d9162 (diff)
downloadnextcloud-server-9f5433c0c3050c61e3e1cc2b7a71352dfe7f9250.tar.gz
nextcloud-server-9f5433c0c3050c61e3e1cc2b7a71352dfe7f9250.zip
Merge pull request #13368 from owncloud/memcache_lowlatency
Refactor \OC\Memcache\Factory
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php4
-rw-r--r--lib/private/memcache/cache.php2
-rw-r--r--lib/private/memcache/factory.php91
-rw-r--r--lib/private/server.php6
4 files changed, 63 insertions, 40 deletions
diff --git a/lib/base.php b/lib/base.php
index 84616090ec8..e957d6be089 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -726,8 +726,8 @@ class OC {
$instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null);
if ($instanceId) {
try {
- $memcacheFactory = new \OC\Memcache\Factory($instanceId);
- self::$loader->setMemoryCache($memcacheFactory->createLowLatency('Autoloader'));
+ $memcacheFactory = \OC::$server->getMemCacheFactory();
+ self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader'));
} catch (\Exception $ex) {
}
}
diff --git a/lib/private/memcache/cache.php b/lib/private/memcache/cache.php
index 03671b3f240..c606d94fa51 100644
--- a/lib/private/memcache/cache.php
+++ b/lib/private/memcache/cache.php
@@ -8,7 +8,7 @@
namespace OC\Memcache;
-abstract class Cache implements \ArrayAccess {
+abstract class Cache implements \ArrayAccess, \OCP\ICache {
/**
* @var string $prefix
*/
diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php
index e8a91c52269..f70f8c7c27a 100644
--- a/lib/private/memcache/factory.php
+++ b/lib/private/memcache/factory.php
@@ -11,77 +11,96 @@ namespace OC\Memcache;
use \OCP\ICacheFactory;
class Factory implements ICacheFactory {
+ const NULL_CACHE = '\\OC\\Memcache\\Null';
+
/**
* @var string $globalPrefix
*/
private $globalPrefix;
/**
+ * @var string $localCacheClass
+ */
+ private $localCacheClass;
+
+ /**
+ * @var string $distributedCacheClass
+ */
+ private $distributedCacheClass;
+
+ /**
* @param string $globalPrefix
+ * @param string|null $localCacheClass
+ * @param string|null $distributedCacheClass
*/
- public function __construct($globalPrefix) {
+ public function __construct($globalPrefix,
+ $localCacheClass = null, $distributedCacheClass = null)
+ {
$this->globalPrefix = $globalPrefix;
+
+ if (!($localCacheClass && $localCacheClass::isAvailable())) {
+ $localCacheClass = self::NULL_CACHE;
+ }
+ if (!($distributedCacheClass && $distributedCacheClass::isAvailable())) {
+ $distributedCacheClass = $localCacheClass;
+ }
+ $this->localCacheClass = $localCacheClass;
+ $this->distributedCacheClass = $distributedCacheClass;
}
/**
- * get a cache instance, or Null backend if no backend available
+ * create a distributed cache instance
*
* @param string $prefix
* @return \OC\Memcache\Cache
*/
- function create($prefix = '') {
- $prefix = $this->globalPrefix . '/' . $prefix;
- if (XCache::isAvailable()) {
- return new XCache($prefix);
- } elseif (APCu::isAvailable()) {
- return new APCu($prefix);
- } elseif (APC::isAvailable()) {
- return new APC($prefix);
- } elseif (Redis::isAvailable()) {
- return new Redis($prefix);
- } elseif (Memcached::isAvailable()) {
- return new Memcached($prefix);
- } else {
- return new ArrayCache($prefix);
- }
+ public function createDistributed($prefix = '') {
+ return new $this->distributedCacheClass($this->globalPrefix . '/' . $prefix);
+ }
+
+ /**
+ * create a local cache instance
+ *
+ * @param string $prefix
+ * @return \OC\Memcache\Cache
+ */
+ public function createLocal($prefix = '') {
+ return new $this->localCacheClass($this->globalPrefix . '/' . $prefix);
+ }
+
+ /**
+ * @see \OC\Memcache\Factory::createDistributed()
+ * @param string $prefix
+ * @return \OC\Memcache\Cache
+ */
+ public function create($prefix = '') {
+ return $this->createDistributed($prefix);
}
/**
- * check if there is a memcache backend available
+ * check memcache availability
*
* @return bool
*/
public function isAvailable() {
- return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable() || Redis::isAvailable() || Memcached::isAvailable();
+ return ($this->distributedCacheClass !== self::NULL_CACHE);
}
/**
- * get a in-server cache instance, will return null if no backend is available
- *
+ * @see \OC\Memcache\Factory::createLocal()
* @param string $prefix
- * @return null|Cache
+ * @return \OC\Memcache\Cache|null
*/
public function createLowLatency($prefix = '') {
- $prefix = $this->globalPrefix . '/' . $prefix;
- if (XCache::isAvailable()) {
- return new XCache($prefix);
- } elseif (APCu::isAvailable()) {
- return new APCu($prefix);
- } elseif (APC::isAvailable()) {
- return new APC($prefix);
- } else {
- return null;
- }
+ return $this->createLocal($prefix);
}
/**
- * check if there is a in-server backend available
+ * check local memcache availability
*
* @return bool
*/
public function isAvailableLowLatency() {
- return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable();
+ return ($this->localCacheClass !== self::NULL_CACHE);
}
-
-
}
diff --git a/lib/private/server.php b/lib/private/server.php
index 18d996537e2..896abf04a40 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -155,8 +155,12 @@ class Server extends SimpleContainer implements IServerContainer {
return new UserCache();
});
$this->registerService('MemCacheFactory', function ($c) {
+ $config = $c->getConfig();
$instanceId = \OC_Util::getInstanceId();
- return new \OC\Memcache\Factory($instanceId);
+ return new \OC\Memcache\Factory($instanceId,
+ $config->getSystemValue('memcache.local', null),
+ $config->getSystemValue('memcache.distributed', null)
+ );
});
$this->registerService('ActivityManager', function ($c) {
return new ActivityManager();