本文整理汇总了PHP中Drupal\Core\Cache\Cache::buildTags方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::buildTags方法的具体用法?PHP Cache::buildTags怎么用?PHP Cache::buildTags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Cache\Cache
的用法示例。
在下文中一共展示了Cache::buildTags方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* {@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;
}
示例2: generate
/**
* {@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;
}
示例3: save
/**
* {@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;
}
示例4: testBuildTags
/**
* @covers buildTags
*
* @dataProvider buildTagsProvider
*/
public function testBuildTags($prefix, array $suffixes, array $expected)
{
$this->assertEquals($expected, Cache::buildTags($prefix, $suffixes));
}
示例5: save
/**
* {@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;
}