diff options
Diffstat (limited to 'lib/private/Group/DisplayNameCache.php')
-rw-r--r-- | lib/private/Group/DisplayNameCache.php | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/lib/private/Group/DisplayNameCache.php b/lib/private/Group/DisplayNameCache.php index d724b6caf0e..fef8d40a05f 100644 --- a/lib/private/Group/DisplayNameCache.php +++ b/lib/private/Group/DisplayNameCache.php @@ -1,34 +1,17 @@ <?php declare(strict_types=1); - /** - * @copyright 2022 Anna Larch <anna.larch@gmx.net> - * @author Anna Larch <anna.larch@gmx.net> - * - * @license AGPL-3.0-or-later - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - - namespace OC\Group; use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Group\Events\GroupChangedEvent; +use OCP\Group\Events\GroupDeletedEvent; use OCP\ICache; use OCP\ICacheFactory; use OCP\IGroupManager; @@ -37,6 +20,7 @@ use OCP\IGroupManager; * Class that cache the relation Group ID -> Display name * * This saves fetching the group from the backend for "just" the display name + * @template-implements IEventListener<GroupChangedEvent|GroupDeletedEvent> */ class DisplayNameCache implements IEventListener { private CappedMemoryCache $cache; @@ -83,5 +67,10 @@ class DisplayNameCache implements IEventListener { $this->cache[$groupId] = $newDisplayName; $this->memCache->set($groupId, $newDisplayName, 60 * 10); // 10 minutes } + if ($event instanceof GroupDeletedEvent) { + $groupId = $event->getGroup()->getGID(); + unset($this->cache[$groupId]); + $this->memCache->remove($groupId); + } } } |