diff --git a/core/lib/Drupal/Core/Session/PermissionsHashGenerator.php b/core/lib/Drupal/Core/Session/PermissionsHashGenerator.php
index f176afd..e421ff6 100644
--- a/core/lib/Drupal/Core/Session/PermissionsHashGenerator.php
+++ b/core/lib/Drupal/Core/Session/PermissionsHashGenerator.php
@@ -33,6 +33,11 @@ class PermissionsHashGenerator implements PermissionsHashGeneratorInterface {
   protected $cache;
 
   /**
+   * The permissions hashes.
+   */
+  protected $hashes = [];
+
+  /**
    * Constructs a PermissionsHashGenerator object.
    *
    * @param \Drupal\Core\PrivateKey $private_key
@@ -54,13 +59,19 @@ public function generate(AccountInterface $account) {
     $sorted_roles = $account->getRoles();
     sort($sorted_roles);
     $role_list = implode(',', $sorted_roles);
-    if ($cache = $this->cache->get("user_permissions_hash:$role_list")) {
-      $permissions_hash = $cache->data;
+    if (isset($this->hashes[$role_list])) {
+      return $this->hashes[$role_list];
     }
     else {
-      $permissions_hash = $this->doGenerate($sorted_roles);
-      $tags = Cache::buildTags('config:user.role', $sorted_roles, '.');
-      $this->cache->set("user_permissions_hash:$role_list", $permissions_hash, Cache::PERMANENT, $tags);
+      if ($cache = $this->cache->get("user_permissions_hash:$role_list")) {
+        $permissions_hash = $cache->data;
+      }
+      else {
+        $permissions_hash = $this->doGenerate($sorted_roles);
+        $tags = Cache::buildTags('config:user.role', $sorted_roles, '.');
+        $this->cache->set("user_permissions_hash:$role_list", $permissions_hash, Cache::PERMANENT, $tags);
+      }
+      $this->hashes[$role_list] = $permissions_hash;
     }
 
     return $permissions_hash;
diff --git a/core/modules/user/src/Tests/UserPermissionsTest.php b/core/modules/user/src/Tests/UserPermissionsTest.php
index 9108fc3..75d4ca9 100644
--- a/core/modules/user/src/Tests/UserPermissionsTest.php
+++ b/core/modules/user/src/Tests/UserPermissionsTest.php
@@ -6,7 +6,7 @@
  */
 
 namespace Drupal\user\Tests;
-
+use Drupal\Core\Session\PermissionsHashGenerator;
 use Drupal\simpletest\WebTestBase;
 use Drupal\user\RoleInterface;
 use Drupal\user\Entity\Role;
@@ -49,8 +49,6 @@ protected function setUp() {
    * Test changing user permissions through the permissions page.
    */
   function testUserPermissionChanges() {
-    $permissions_hash_generator = $this->container->get('user_permissions_hash_generator');
-
     $storage = $this->container->get('entity.manager')->getStorage('user_role');
 
     // Create an additional role and mark it as admin role.
@@ -60,6 +58,7 @@ function testUserPermissionChanges() {
     $this->drupalLogin($this->adminUser);
     $rid = $this->rid;
     $account = $this->adminUser;
+    $permissions_hash_generator = new PermissionsHashGenerator($this->container->get('private_key'), $this->container->get('cache.data'));
     $previous_permissions_hash = $permissions_hash_generator->generate($account);
     $this->assertIdentical($previous_permissions_hash, $permissions_hash_generator->generate($this->loggedInUser));
 
@@ -71,6 +70,7 @@ function testUserPermissionChanges() {
     $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
     $storage->resetCache();
     $this->assertTrue($account->hasPermission('administer users'), 'User now has "administer users" permission.');
+    $permissions_hash_generator = new PermissionsHashGenerator($this->container->get('private_key'), $this->container->get('cache.data'));
     $current_permissions_hash = $permissions_hash_generator->generate($account);
     $this->assertIdentical($current_permissions_hash, $permissions_hash_generator->generate($this->loggedInUser));
     $this->assertNotEqual($previous_permissions_hash, $current_permissions_hash, 'Permissions hash has changed.');
@@ -84,6 +84,7 @@ function testUserPermissionChanges() {
     $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
     $storage->resetCache();
     $this->assertFalse($account->hasPermission('access user profiles'), 'User no longer has "access user profiles" permission.');
+    $permissions_hash_generator = new PermissionsHashGenerator($this->container->get('private_key'), $this->container->get('cache.data'));
     $current_permissions_hash = $permissions_hash_generator->generate($account);
     $this->assertIdentical($current_permissions_hash, $permissions_hash_generator->generate($this->loggedInUser));
     $this->assertNotEqual($previous_permissions_hash, $current_permissions_hash, 'Permissions hash has changed.');
@@ -166,6 +167,7 @@ function testUserRoleChangePermissions() {
     $this->assertTrue($account->hasPermission('administer site configuration'), 'User still has "administer site configuration" permission.');
 
     // Verify the permissions hash has changed.
+    $permissions_hash_generator = new PermissionsHashGenerator($this->container->get('private_key'), $this->container->get('cache.data'));
     $current_permissions_hash = $permissions_hash_generator->generate($account);
     $this->assertNotEqual($previous_permissions_hash, $current_permissions_hash, 'Permissions hash has changed.');
   }
