diff --git a/core/modules/user/src/RoleStorage.php b/core/modules/user/src/RoleStorage.php index a88a1d2..947a883 100644 --- a/core/modules/user/src/RoleStorage.php +++ b/core/modules/user/src/RoleStorage.php @@ -36,19 +36,19 @@ public function isPermissionInRoles($permission, array $rids) { public function resetCache(array $ids = NULL) { parent::resetCache($ids); + // Clear all static cache. if ($ids === NULL) { - // Clear all static cache. drupal_static_reset('user_roles'); } - elseif ($ids) { - // Remove only roles from $ids list. - if ($user_roles =& drupal_static('user_roles')) { - $user_roles = array_map(function (array $roles) use ($ids) { - return array_filter($roles, function (RoleInterface $role) use ($ids) { - return !in_array($role->id(), $ids); - }); - }, $user_roles); - } + // Selective clear the static cache. + elseif ($ids && $user_roles = &drupal_static('user_roles')) { + // Remove the entire cache cid, if at least one role has to be cleared. + // The cache cid can be either RoleInterface::ANONYMOUS_ID, either + // RoleInterface::AUTHENTICATED_ID. + // @see user_roles() + $user_roles = array_filter($user_roles, function (array $roles) use ($ids) { + return array_intersect(array_keys($roles), $ids); + }); } }