Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Cache] Improved the example about cache tags#12398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 3 commits intosymfony:4.3fromjaviereguiluz:pr/12181
Oct 1, 2019
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletionscache.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -487,21 +487,36 @@ use cache tags. One or more tags could be added to the cache item. All items wit
the same key could be invalidate with one function call::

use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;

$value0 = $pool->get('item_0', function (ItemInterface $item) {
$item->tag(['foo', 'bar']);
class SomeClass
{
private $myCachePool;

return 'debug';
});
// using autowiring to inject the cache pool
public function __construct(TagAwareCacheInterface $myCachePool)
{
$this->myCachePool = $myCachePool;
}

$value1 = $pool->get('item_1', function (ItemInterface $item) {
$item->tag('foo');
public function someMethod()
{
$value0 = $this->myCachePool->get('item_0', function (ItemInterface $item) {
$item->tag(['foo', 'bar']);

return 'debug';
});
return 'debug';
});

// Remove all cache keys tagged with "bar"
$pool->invalidateTags(['bar']);
$value1 = $this->myCachePool->get('item_1', function (ItemInterface $item) {
$item->tag('foo');

return 'debug';
});

// Remove all cache keys tagged with "bar"
$this->myCachePool->invalidateTags(['bar']);
}
}

The cache adapter needs to implement :class:`Symfony\\Contracts\\Cache\\TagAwareCacheInterface``
to enable this feature. This could be added by using the following configuration.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp