Remove the static dependency on OC_Util from Memcache

This commit is contained in:
Robin Appelman 2014-01-06 13:11:38 +01:00
parent cd147bb37a
commit 4d65a80892
4 changed files with 23 additions and 2 deletions

View file

@ -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() {

View file

@ -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()) {

View file

@ -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) {

View file

@ -141,6 +141,13 @@ interface IServerContainer {
*/
function getCache();
/**
* Returns an ICache instance
*
* @return \OCP\ICache
*/
function getMemCache();
/**
* Returns the current session
*