From 4d65a8089284e4dde09181b56fb45b86c50d6fb5 Mon Sep 17 00:00:00 2001 From: Robin Appelman <icewind@owncloud.com> Date: Mon, 6 Jan 2014 13:11:38 +0100 Subject: [PATCH] Remove the static dependency on OC_Util from Memcache --- lib/private/memcache/cache.php | 2 +- lib/private/memcache/factory.php | 13 +++++++++++++ lib/private/server.php | 3 ++- lib/public/iservercontainer.php | 7 +++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/private/memcache/cache.php b/lib/private/memcache/cache.php index 0ad1cc7ec0..03671b3f24 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 fde7d94756..48c97b5955 100644 --- a/lib/private/memcache/factory.php +++ b/lib/private/memcache/factory.php @@ -9,6 +9,18 @@ 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 * @@ -16,6 +28,7 @@ class Factory { * @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 84ee8cadf0..6b242bddd0 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -137,7 +137,8 @@ class Server extends SimpleContainer implements IServerContainer { return new UserCache(); }); $this->registerService('MemCache', function ($c) { - $factory = new \OC\Memcache\Factory(); + $instanceId = \OC_Util::getInstanceId(); + $factory = new \OC\Memcache\Factory($instanceId); return $factory->create(); }); $this->registerService('ActivityManager', function($c) { diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index b958d2d03f..7ac5049ef2 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -141,6 +141,13 @@ interface IServerContainer { */ function getCache(); + /** + * Returns an ICache instance + * + * @return \OCP\ICache + */ + function getMemCache(); + /** * Returns the current session * -- GitLab