namespace OC\L10N;
+use OCP\ICache;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
protected $request;
/** @var IUserSession */
- protected $userSession;
+ protected IUserSession $userSession;
+
+ private ICache $cache;
/** @var string */
protected $serverRoot;
IConfig $config,
IRequest $request,
IUserSession $userSession,
+ ICacheFactory $cacheFactory,
$serverRoot
) {
$this->config = $config;
$this->request = $request;
$this->userSession = $userSession;
+ $this->cache = $cacheFactory->createLocal('L10NFactory');
$this->serverRoot = $serverRoot;
}
$key = 'null';
}
+ if ($availableLanguages = $this->cache->get($key)) {
+ $this->availableLanguages[$key] = $availableLanguages;
+ }
+
// also works with null as key
if (!empty($this->availableLanguages[$key])) {
return $this->availableLanguages[$key];
}
$this->availableLanguages[$key] = $available;
+ $this->cache->set($key, $available, 60);
return $available;
}
$c->get(\OCP\IConfig::class),
$c->getRequest(),
$c->get(IUserSession::class),
+ $c->get(ICacheFactory::class),
\OC::$SERVERROOT
);
});
use OC\L10N\Factory;
use OC\L10N\LanguageNotFoundException;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
/** @var IUserSession|MockObject */
protected $userSession;
+ /** @var ICacheFactory|MockObject */
+ protected $cacheFactory;
+
/** @var string */
protected $serverRoot;
$this->config = $this->createMock(IConfig::class);
$this->request = $this->createMock(IRequest::class);
$this->userSession = $this->createMock(IUserSession::class);
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->serverRoot = \OC::$SERVERROOT;
}
$this->config,
$this->request,
$this->userSession,
+ $this->cacheFactory,
$this->serverRoot,
])
->setMethods($methods)
->getMock();
}
- return new Factory($this->config, $this->request, $this->userSession, $this->serverRoot);
+ return new Factory($this->config, $this->request, $this->userSession, $this->cacheFactory, $this->serverRoot);
}
public function dataFindAvailableLanguages(): array {
use DateTime;
use OC\L10N\Factory;
use OC\L10N\L10N;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
$request = $this->createMock(IRequest::class);
/** @var IUserSession $userSession */
$userSession = $this->createMock(IUserSession::class);
- return new Factory($config, $request, $userSession, \OC::$SERVERROOT);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
+ return new Factory($config, $request, $userSession, $cacheFactory, \OC::$SERVERROOT);
}
public function testSimpleTranslationWithTrailingColon(): void {