diff options
author | Anna <anna@nextcloud.com> | 2022-05-12 18:25:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 18:25:45 +0300 |
commit | b2e9746469126759623996cfea870376cdb08486 (patch) | |
tree | 763d184fcdb4d96d43a970cdacf2a98f168a38f6 /lib | |
parent | 5799c301eadcdba95a024b774852cf4e58fc5e2e (diff) | |
parent | aae3d728909f11caa174a98e1d214a3a30298fc6 (diff) |
Merge pull request #6325 from nextcloud/enhancement/cache-provisionings
Cache provisioning configs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Service/Provisioning/Manager.php | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/Service/Provisioning/Manager.php b/lib/Service/Provisioning/Manager.php index 36877b259..7207bbf60 100644 --- a/lib/Service/Provisioning/Manager.php +++ b/lib/Service/Provisioning/Manager.php @@ -34,6 +34,7 @@ use OCA\Mail\Db\TagMapper; use OCA\Mail\Exception\ValidationException; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; +use OCP\ICacheFactory; use OCP\IUser; use OCP\IUserManager; use OCP\LDAP\ILDAPProvider; @@ -67,6 +68,9 @@ class Manager { /** @var TagMapper */ private $tagMapper; + /** @var ICacheFactory */ + private $cacheFactory; + public function __construct(IUserManager $userManager, ProvisioningMapper $provisioningMapper, MailAccountMapper $mailAccountMapper, @@ -74,7 +78,8 @@ class Manager { ILDAPProviderFactory $ldapProviderFactory, AliasMapper $aliasMapper, LoggerInterface $logger, - TagMapper $tagMapper) { + TagMapper $tagMapper, + ICacheFactory $cacheFactory) { $this->userManager = $userManager; $this->provisioningMapper = $provisioningMapper; $this->mailAccountMapper = $mailAccountMapper; @@ -83,6 +88,7 @@ class Manager { $this->aliasMapper = $aliasMapper; $this->logger = $logger; $this->tagMapper = $tagMapper; + $this->cacheFactory = $cacheFactory; } public function getConfigById(int $provisioningId): ?Provisioning { @@ -90,7 +96,21 @@ class Manager { } public function getConfigs(): array { - return $this->provisioningMapper->getAll(); + $cache = null; + if ($this->cacheFactory->isLocalCacheAvailable()) { + $cache = $this->cacheFactory->createLocal('provisionings'); + $cached = $cache->get('provisionings_all'); + if ($cached !== null) { + return unserialize($cached, ['allowed_classes' => [Provisioning::class]]); + } + } + + $provisionings = $this->provisioningMapper->getAll(); + // let's cache the provisionings for 5 minutes + if ($this->cacheFactory->isLocalCacheAvailable()) { + $cache->set('provisionings_all', serialize($provisionings), 60 * 5); + } + return $provisionings; } public function provision(): int { |