private function TeamMembershipManager::invalidateCaches in Apigee Edge 8
Invalidates caches when membership state changes.
Parameters
string $team: Name of a team.
array $developers: Array of developer email addresses.
2 calls to TeamMembershipManager::invalidateCaches()
- TeamMembershipManager::addMembers in modules/
apigee_edge_teams/ src/ TeamMembershipManager.php - Adds members to a team.
- TeamMembershipManager::removeMembers in modules/
apigee_edge_teams/ src/ TeamMembershipManager.php - Removes members from a team.
File
- modules/
apigee_edge_teams/ src/ TeamMembershipManager.php, line 186
Class
- TeamMembershipManager
- Service that makes easier to work with company (team) memberships.
Namespace
Drupal\apigee_edge_teamsCode
private function invalidateCaches(string $team, array $developers) : void {
// At this point we can assume that team entity exists because earlier
// API calls have not fail.
$team_entity = $this->entityTypeManager
->getStorage('team')
->load($team);
// This invalidates every occupancies where $team has appeared.
$tags = $team_entity
->getCacheTags();
// This invalidates cache on team listing page(s) because the list
// of accessible teams for user(s) has changed.
// (If we find this too much, later we can tag team listing pages with a
// "team_list:{$developer_email}" tag and only invalidate those developers'
// team listing pages whose membership state has changed.)
$tags = array_merge($tags, $this->entityTypeManager
->getDefinition('team')
->getListCacheTags());
$this->cacheTagsInvalidator
->invalidateTags($tags);
// Developer::getCompanies() must return the updated membership information.
// @see \Drupal\apigee_edge\Entity\Developer::getCompanies()
$developer_companies_cache_tags = array_map(function (string $developer) {
return "developer:{$developer}";
}, $developers);
$this->developerCompaniesCache
->invalidate($developer_companies_cache_tags);
// Developer controller's cache has to be cleared as well otherwise
// Developer::getCompanies() reloads the old data from the controller's
// cache.
if ($this->developerController instanceof EntityCacheAwareControllerInterface) {
$this->developerController
->entityCache()
->removeEntities($developers);
}
// Enforce re-evaluation of API product entity access.
$this->entityTypeManager
->getAccessControlHandler('api_product')
->resetCache();
// Prevents circular reference between the services:
// apigee_edge_teams.team_permissions ->
// apigee_edge_teams.team_membership_manager ->
// apigee_edge_teams.team_member_api_product_access_handler.
// This call is just a helper for us to ensure the static cache of the
// Team member API Product access handler gets cleared when this method
// gets called. This is especially useful in testing. So calling
// \Drupal::service() should be fine.
\Drupal::service('apigee_edge_teams.team_member_api_product_access_handler')
->resetCache();
}