summaryrefslogtreecommitdiffstats
path: root/lib/private/memcache
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@karoshi.org.uk>2015-01-14 18:25:00 +0000
committerRobin McCorkell <rmccorkell@karoshi.org.uk>2015-03-05 11:36:34 +0000
commit0e4933e6d248ab383e6221e045fec2eaf3d17082 (patch)
tree5a9f368158b61b276276edaba92d6acb2e922e58 /lib/private/memcache
parentf507601e259da2e6b67237ffcfe8eeda880062ef (diff)
downloadnextcloud-server-0e4933e6d248ab383e6221e045fec2eaf3d17082.tar.gz
nextcloud-server-0e4933e6d248ab383e6221e045fec2eaf3d17082.zip
Refactor \OC\Memcache\Factory
Caches divided up into two groups: distributed and local. 'Low latency' is an alias for local caches, while the standard `create()` call tries to get distributed caches first, then local caches. Memcache backend is set in `config.php`, with the keys `memcache.local` and `memcache.distributed`. If not set, `memcache.distributed` defaults to the value of `memcache.local`.
Diffstat (limited to 'lib/private/memcache')
-rw-r--r--lib/private/memcache/factory.php91
1 files changed, 55 insertions, 36 deletions
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);
}
-
-
}