fix: Remove static var in Memcache/Redis

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2026-03-13 11:58:29 +01:00
parent 0a193a3f7e
commit c3db7fa0e8
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
3 changed files with 12 additions and 21 deletions

View file

@ -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]

View file

@ -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;

View file

@ -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');