Skip to content

Commit b2e9746

Browse files
authored
Merge pull request #6325 from nextcloud/enhancement/cache-provisionings
Cache provisioning configs
2 parents 5799c30 + aae3d72 commit b2e9746

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lib/Service/Provisioning/Manager.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCA\Mail\Exception\ValidationException;
3535
use OCP\AppFramework\Db\DoesNotExistException;
3636
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
37+
use OCP\ICacheFactory;
3738
use OCP\IUser;
3839
use OCP\IUserManager;
3940
use OCP\LDAP\ILDAPProvider;
@@ -67,14 +68,18 @@ class Manager {
6768
/** @var TagMapper */
6869
private $tagMapper;
6970

71+
/** @var ICacheFactory */
72+
private $cacheFactory;
73+
7074
public function __construct(IUserManager $userManager,
7175
ProvisioningMapper $provisioningMapper,
7276
MailAccountMapper $mailAccountMapper,
7377
ICrypto $crypto,
7478
ILDAPProviderFactory $ldapProviderFactory,
7579
AliasMapper $aliasMapper,
7680
LoggerInterface $logger,
77-
TagMapper $tagMapper) {
81+
TagMapper $tagMapper,
82+
ICacheFactory $cacheFactory) {
7883
$this->userManager = $userManager;
7984
$this->provisioningMapper = $provisioningMapper;
8085
$this->mailAccountMapper = $mailAccountMapper;
@@ -83,14 +88,29 @@ public function __construct(IUserManager $userManager,
8388
$this->aliasMapper = $aliasMapper;
8489
$this->logger = $logger;
8590
$this->tagMapper = $tagMapper;
91+
$this->cacheFactory = $cacheFactory;
8692
}
8793

8894
public function getConfigById(int $provisioningId): ?Provisioning {
8995
return $this->provisioningMapper->get($provisioningId);
9096
}
9197

9298
public function getConfigs(): array {
93-
return $this->provisioningMapper->getAll();
99+
$cache = null;
100+
if ($this->cacheFactory->isLocalCacheAvailable()) {
101+
$cache = $this->cacheFactory->createLocal('provisionings');
102+
$cached = $cache->get('provisionings_all');
103+
if ($cached !== null) {
104+
return unserialize($cached, ['allowed_classes' => [Provisioning::class]]);
105+
}
106+
}
107+
108+
$provisionings = $this->provisioningMapper->getAll();
109+
// let's cache the provisionings for 5 minutes
110+
if ($this->cacheFactory->isLocalCacheAvailable()) {
111+
$cache->set('provisionings_all', serialize($provisionings), 60 * 5);
112+
}
113+
return $provisionings;
94114
}
95115

96116
public function provision(): int {

0 commit comments

Comments
 (0)