add debug log for memcache instantiation

This commit is contained in:
Jörn Friedrich Dreyer 2015-02-04 12:15:40 +01:00 committed by Thomas Müller
parent 5a5d6bf4db
commit 87db136508
3 changed files with 21 additions and 7 deletions

View File

@ -708,7 +708,8 @@ class OC {
$instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null);
if ($instanceId) { if ($instanceId) {
try { try {
$memcacheFactory = new \OC\Memcache\Factory($instanceId); $memcacheFactory = new \OC\Memcache\Factory($instanceId,
\OC::$server->getLogger());
self::$loader->setMemoryCache($memcacheFactory->createLowLatency('Autoloader')); self::$loader->setMemoryCache($memcacheFactory->createLowLatency('Autoloader'));
} catch (\Exception $ex) { } catch (\Exception $ex) {
} }

View File

@ -11,16 +11,19 @@ namespace OC\Memcache;
use \OCP\ICacheFactory; use \OCP\ICacheFactory;
class Factory implements ICacheFactory { class Factory implements ICacheFactory {
/** /** @var string $globalPrefix */
* @var string $globalPrefix
*/
private $globalPrefix; private $globalPrefix;
/** @var \OCP\ILogger */
private $logger;
/** /**
* @param string $globalPrefix * @param string $globalPrefix
* @param \OCP\ILogger $logger
*/ */
public function __construct($globalPrefix) { public function __construct($globalPrefix, $logger) {
$this->globalPrefix = $globalPrefix; $this->globalPrefix = $globalPrefix;
$this->logger = $logger;
} }
/** /**
@ -32,16 +35,22 @@ class Factory implements ICacheFactory {
function create($prefix = '') { function create($prefix = '') {
$prefix = $this->globalPrefix . '/' . $prefix; $prefix = $this->globalPrefix . '/' . $prefix;
if (XCache::isAvailable()) { if (XCache::isAvailable()) {
$this->logger->debug("creating XCache instance", array('app' => 'memcache'));
return new XCache($prefix); return new XCache($prefix);
} elseif (APCu::isAvailable()) { } elseif (APCu::isAvailable()) {
$this->logger->debug('creating APCu instance', array('app'=>'memcache'));
return new APCu($prefix); return new APCu($prefix);
} elseif (APC::isAvailable()) { } elseif (APC::isAvailable()) {
$this->logger->debug('creating APC instance', array('app'=>'memcache'));
return new APC($prefix); return new APC($prefix);
} elseif (Redis::isAvailable()) { } elseif (Redis::isAvailable()) {
$this->logger->debug('creating redis instance', array('app'=>'memcache'));
return new Redis($prefix); return new Redis($prefix);
} elseif (Memcached::isAvailable()) { } elseif (Memcached::isAvailable()) {
$this->logger->debug('creating memcached instance', array('app'=>'memcache'));
return new Memcached($prefix); return new Memcached($prefix);
} else { } else {
$this->logger->debug('no cache available instance', array('app'=>'memcache'));
return new ArrayCache($prefix); return new ArrayCache($prefix);
} }
} }
@ -64,12 +73,16 @@ class Factory implements ICacheFactory {
public function createLowLatency($prefix = '') { public function createLowLatency($prefix = '') {
$prefix = $this->globalPrefix . '/' . $prefix; $prefix = $this->globalPrefix . '/' . $prefix;
if (XCache::isAvailable()) { if (XCache::isAvailable()) {
$this->logger->debug('creating xcache instance for low latency', array('app'=>'memcache'));
return new XCache($prefix); return new XCache($prefix);
} elseif (APCu::isAvailable()) { } elseif (APCu::isAvailable()) {
$this->logger->debug('creating APCu instance for low latency', array('app'=>'memcache'));
return new APCu($prefix); return new APCu($prefix);
} elseif (APC::isAvailable()) { } elseif (APC::isAvailable()) {
$this->logger->debug('creating APC instance for low latency', array('app'=>'memcache'));
return new APC($prefix); return new APC($prefix);
} else { } else {
$this->logger->debug('no low latency cache available', array('app'=>'memcache'));
return null; return null;
} }
} }
@ -83,5 +96,4 @@ class Factory implements ICacheFactory {
return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable(); return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable();
} }
} }

View File

@ -193,7 +193,8 @@ class Server extends SimpleContainer implements IServerContainer {
}); });
$this->registerService('MemCacheFactory', function ($c) { $this->registerService('MemCacheFactory', function ($c) {
$instanceId = \OC_Util::getInstanceId(); $instanceId = \OC_Util::getInstanceId();
return new \OC\Memcache\Factory($instanceId); $logger = $c['Logger'];
return new \OC\Memcache\Factory($instanceId, $logger);
}); });
$this->registerService('ActivityManager', function ($c) { $this->registerService('ActivityManager', function ($c) {
return new ActivityManager(); return new ActivityManager();