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

Commitcd6b150

Browse files
committed
minor#12398 [Cache] Improved the example about cache tags (pavelmaca, javiereguiluz)
This PR was merged into the 4.3 branch.Discussion----------[Cache] Improved the example about cache tagsThis continues the work started in#12181.Commits-------f9d438f Fixed code2651f92 [Cache] Improved the example about cache tagsce0c625 [Cache] Fix example for using cache tags with TagAwareCacheInterface
2 parents358b8c5 +f9d438f commitcd6b150

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

‎cache.rst‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -489,23 +489,33 @@ the same key could be invalidate with one function call::
489489
use Symfony\Contracts\Cache\ItemInterface;
490490
use Symfony\Contracts\Cache\TagAwareCacheInterface;
491491

492-
// using autowiring
493-
public function listProducts(TagAwareCacheInterface $pool)
492+
class SomeClass
494493
{
495-
$value0 = $pool->get('item_0', function (ItemInterface $item) {
496-
$item->tag(['foo', 'bar']);
494+
private $myCachePool;
497495

498-
return 'debug';
499-
});
496+
// using autowiring to inject the cache pool
497+
public function __construct(TagAwareCacheInterface $myCachePool)
498+
{
499+
$this->myCachePool = $myCachePool;
500+
}
500501

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

504-
return 'debug';
505-
});
507+
return 'debug';
508+
});
506509

507-
// Remove all cache keys tagged with "bar"
508-
$pool->invalidateTags(['bar']);
510+
$value1 = $this->myCachePool->get('item_1', function (ItemInterface $item) {
511+
$item->tag('foo');
512+
513+
return 'debug';
514+
});
515+
516+
// Remove all cache keys tagged with "bar"
517+
$this->myCachePool->invalidateTags(['bar']);
518+
}
509519
}
510520

511521
The cache adapter needs to implement:class:`Symfony\\Contracts\\Cache\\TagAwareCacheInterface``

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp