Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Drop custom cache handling #729

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 0 additions & 38 deletions src/Og.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
10 changes: 0 additions & 10 deletions tests/src/Kernel/Entity/GetUserGroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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, [
Expand All @@ -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, [
Expand Down