/** * {@inheritdoc} * * Cached by role, invalidated whenever permissions change. */ public function generate(AccountInterface $account) { // User 1 is the super user, and can always access all permissions. Use a // different, unique identifier for the hash. if ($account->id() == 1) { return $this->hash('is-super-user'); } $sorted_roles = $account->getRoles(); sort($sorted_roles); $role_list = implode(',', $sorted_roles); $cid = "user_permissions_hash:{$role_list}"; if ($static_cache = $this->static->get($cid)) { return $static_cache->data; } else { $tags = Cache::buildTags('config:user.role', $sorted_roles, '.'); if ($cache = $this->cache->get($cid)) { $permissions_hash = $cache->data; } else { $permissions_hash = $this->doGenerate($sorted_roles); $this->cache->set($cid, $permissions_hash, Cache::PERMANENT, $tags); } $this->static->set($cid, $permissions_hash, Cache::PERMANENT, $tags); } return $permissions_hash; }
/** * {@inheritdoc} * * Cached by role, invalidated whenever permissions change. */ 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; } 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); } return $permissions_hash; }
/** * {@inheritdoc} */ public function save(array $link) { $affected_menus = $this->doSave($link); $this->resetDefinitions(); $cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.'); $this->cacheTagsInvalidator->invalidateTags($cache_tags); return $affected_menus; }
/** * @covers buildTags * * @dataProvider buildTagsProvider */ public function testBuildTags($prefix, array $suffixes, array $expected) { $this->assertEquals($expected, Cache::buildTags($prefix, $suffixes)); }
/** * {@inheritdoc} */ public function save(array $link) { $affected_menus = $this->doSave($link); $this->resetDefinitions(); $cache_tags = Cache::buildTags('menu', $affected_menus); Cache::invalidateTags($cache_tags); return $affected_menus; }