mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 10:10:49 -04:00
fix: Remove static var in Memcache/Redis
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
0a193a3f7e
commit
c3db7fa0e8
3 changed files with 12 additions and 21 deletions
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
namespace OC\Memcache;
|
||||
|
||||
use OC\RedisFactory;
|
||||
use OCP\IMemcacheTTL;
|
||||
use OCP\Server;
|
||||
|
||||
|
|
@ -38,24 +39,18 @@ class Redis extends Cache implements IMemcacheTTL {
|
|||
|
||||
private const MAX_TTL = 30 * 24 * 60 * 60; // 1 month
|
||||
|
||||
/**
|
||||
* @var \Redis|\RedisCluster $cache
|
||||
*/
|
||||
private static $cache = null;
|
||||
private \Redis|\RedisCluster $cache;
|
||||
|
||||
public function __construct($prefix = '', string $logFile = '') {
|
||||
parent::__construct($prefix);
|
||||
$this->cache = \OCP\Server::get(RedisFactory::class)->getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Redis|\RedisCluster|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getCache() {
|
||||
if (is_null(self::$cache)) {
|
||||
self::$cache = Server::get('RedisFactory')->getInstance();
|
||||
}
|
||||
return self::$cache;
|
||||
public function getCache(): \Redis|\RedisCluster {
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
|
|
|
|||
|
|
@ -131,15 +131,14 @@ class RedisFactory {
|
|||
}
|
||||
|
||||
public function getInstance(): \Redis|\RedisCluster {
|
||||
if (!$this->isAvailable()) {
|
||||
throw new \Exception('Redis support is not available');
|
||||
}
|
||||
if ($this->instance === null) {
|
||||
if (!$this->isAvailable()) {
|
||||
throw new \Exception('Redis support is not available');
|
||||
}
|
||||
$this->create();
|
||||
}
|
||||
|
||||
if ($this->instance === null) {
|
||||
throw new \Exception('Redis support is not available');
|
||||
if ($this->instance === null) {
|
||||
throw new \Exception('Redis support is not available');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->instance;
|
||||
|
|
|
|||
|
|
@ -660,10 +660,7 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
});
|
||||
$this->registerAlias(ICacheFactory::class, Factory::class);
|
||||
|
||||
$this->registerService('RedisFactory', function (Server $c) {
|
||||
$systemConfig = $c->get(SystemConfig::class);
|
||||
return new RedisFactory($systemConfig, $c->get(IEventLogger::class));
|
||||
});
|
||||
$this->registerDeprecatedAlias('RedisFactory', RedisFactory::class);
|
||||
|
||||
$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
|
||||
$l10n = $this->get(IFactory::class)->get('lib');
|
||||
|
|
|
|||
Loading…
Reference in a new issue