From aadc01567d72885c2d06afcf52e495a69ad15550 Mon Sep 17 00:00:00 2001 From: Aron Novak Date: Fri, 5 Nov 2021 15:11:39 +0100 Subject: [PATCH] drop custom cache handling --- og.module | 5 --- src/Og.php | 38 ------------------- tests/src/Kernel/Entity/GetUserGroupsTest.php | 10 ----- 3 files changed, 53 deletions(-) diff --git a/og.module b/og.module index 9f7ed92ae..099daa8c8 100755 --- a/og.module +++ b/og.module @@ -107,11 +107,6 @@ function og_entity_delete(EntityInterface $entity) { // Invalidate cache tags after a group or group content entity is deleted. og_invalidate_group_content_cache_tags($entity); - // Clear static caches after a group or group content entity is deleted. - if (Og::isGroup($entity->getEntityTypeId(), $entity->bundle()) || Og::isGroupContent($entity->getEntityTypeId(), $entity->bundle())) { - Og::invalidateCache(); - } - // If a group content type is deleted, make sure to remove it from the list of // groups. if ($entity instanceof ConfigEntityBundleBase) { diff --git a/src/Og.php b/src/Og.php index 26bca32a4..6e43c0c6d 100644 --- a/src/Og.php +++ b/src/Og.php @@ -79,9 +79,6 @@ public static function createField($plugin_id, $entity_type, $bundle, array $set $field_definition = FieldConfig::create($field_config); $field_definition->save(); - - // @todo Verify this is still needed here. - static::invalidateCache(); } // Make the field visible in the default form display. @@ -329,41 +326,6 @@ public static function groupTypeManager() { return \Drupal::service('og.group_type_manager'); } - /** - * Invalidate cache. - */ - public static function invalidateCache() { - // @todo We should not be using drupal_static() review and remove. - // Reset static cache. - $caches = [ - 'og_user_access', - 'og_user_access_alter', - 'og_role_permissions', - 'og_get_user_roles', - 'og_get_permissions', - 'og_get_entity_groups', - 'og_get_membership', - 'og_get_field_og_membership_properties', - 'og_get_user_roles', - ]; - - foreach ($caches as $cache) { - drupal_static_reset($cache); - } - - // @todo Consider using a reset() method. - static::$cache = []; - - // Invalidate the entity property cache. - // @todo We should not clear the entity type and field definition caches. - // @see https://github.com/Gizra/og/issues/219 - \Drupal::entityTypeManager()->clearCachedDefinitions(); - \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions(); - - // Let other OG modules know we invalidate cache. - \Drupal::moduleHandler()->invokeAll('og_invalidate_cache'); - } - /** * Get an OG field base definition. * diff --git a/tests/src/Kernel/Entity/GetUserGroupsTest.php b/tests/src/Kernel/Entity/GetUserGroupsTest.php index edd3cdb45..caadd6161 100644 --- a/tests/src/Kernel/Entity/GetUserGroupsTest.php +++ b/tests/src/Kernel/Entity/GetUserGroupsTest.php @@ -166,10 +166,6 @@ public function testOtherGroups() { $this->assertFalse(Og::isMember($this->group1, $this->user3)); $this->assertFalse(Og::isMember($this->group2, $this->user3)); - // Invalidate the caches so the static cache is cleared and group data is - // fetched again for the user. - Og::invalidateCache(); - // Add user to group 1 should now return that group only. $this->createOgMembership($this->group1, $this->user3); @@ -181,8 +177,6 @@ public function testOtherGroups() { $this->assertTrue(Og::isMember($this->group1, $this->user3)); $this->assertFalse(Og::isMember($this->group2, $this->user3)); - Og::invalidateCache(); - // Add to group 2 should also return that. $this->createOgMembership($this->group2, $this->user3); @@ -220,8 +214,6 @@ public function testIsMemberStates() { // Change the membership state to PENDING. $membership->setState(OgMembershipInterface::STATE_PENDING)->save(); - Og::invalidateCache(); - $this->assertTrue(Og::isMember($this->group1, $this->user3, [OgMembershipInterface::STATE_PENDING])); $this->assertTrue(Og::isMemberPending($this->group1, $this->user3)); $this->assertTrue(Og::isMember($this->group1, $this->user3, [ @@ -236,8 +228,6 @@ public function testIsMemberStates() { // Change the membership state to BLOCKED. $membership->setState(OgMembershipInterface::STATE_BLOCKED)->save(); - Og::invalidateCache(); - $this->assertTrue(Og::isMember($this->group1, $this->user3, [OgMembershipInterface::STATE_BLOCKED])); $this->assertTrue(Og::isMemberBlocked($this->group1, $this->user3)); $this->assertTrue(Og::isMember($this->group1, $this->user3, [