Skip to content

Commit

Permalink
[apigee#408] Fix team lists cache errors - updated cache tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
arlina-espinoza committed Jun 8, 2020
1 parent 17c30da commit 872759e
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,26 @@ public function buildRow(EntityInterface $entity) {
*/
public function render() {
$build = parent::render();
$account = $this->entityTypeManager->getStorage('user')->load(\Drupal::currentUser()->id());

// Team lists vary for each user.
$build['#cache']['contexts'][] = 'user';
$build['#cache']['tags'][] = 'user:' . \Drupal::currentUser()->id();
$build['#cache']['max-age'] = 0;

// This team list should be invalidated if the user's permissions change.
$build['#cache']['tags'][] = 'user:' . $account->id();

// This team list should be invalidated if the user roles permissions change.
foreach ($account->getRoles() as $rid) {
$build['#cache']['tags'][] = "config:user.role.$rid";
}

// This team list should be invalidated if the team roles permissions change.
$build['#cache']['tags'][] = 'team_role_list';

// Use cache expiration defined in configuration.
$build['#cache']['max-age'] = $this->configFactory
->get('apigee_edge_teams.team_settings')
->get('cache_expiration');

return $build;
}
Expand Down

0 comments on commit 872759e

Please sign in to comment.