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

Add a cache tag to invalidate a group's user membership listings #483

Merged
merged 7 commits into from
Apr 30, 2019
10 changes: 7 additions & 3 deletions src/Entity/OgMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,10 @@ protected function invalidateTagsOnSave($update) {
// membership listings because it now meets those listings' filtering
// requirements. A newly created membership may start to appear in listings
// because it did not exist before.
$tags = Cache::buildTags('og-group-membership-list', $this->getGroup()->getCacheTagsToInvalidate());
Cache::invalidateTags($tags);
if ($group = $this->getGroup()) {
$tags = Cache::buildTags('og-group-membership-list', $group->getCacheTagsToInvalidate());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a constant instead of 'og-group-membership-list'?

Cache::invalidateTags($tags);
}
}

/**
Expand All @@ -509,7 +511,9 @@ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_typ
// will be recalculated.
$tags = [];
foreach ($entities as $entity) {
$tags = Cache::mergeTags(Cache::buildTags('og-group-membership-list', $entity->getGroup()->getCacheTagsToInvalidate()), $tags);
if ($group = $entity->getGroup()) {
$tags = Cache::mergeTags(Cache::buildTags('og-group-membership-list', $group->getCacheTagsToInvalidate()), $tags);
}
}
Cache::invalidateTags($tags);
}
Expand Down