8000 Merge branch '4.3' into 4.4 · symfony/symfony-docs@60f1409 · GitHub
[go: up one dir, main page]

Skip to content

Commit 60f1409

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [Cache] Improved the example about cache tags
2 parents c13d6ee + cd6b150 commit 60f1409

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

cache.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -447,21 +447,36 @@ use cache tags. One or more tags could be added to the cache item. All items wit
447447
the same key could be invalidate with one function call::
448448

449449
use Symfony\Contracts\Cache\ItemInterface;
450+
use Symfony\Contracts\Cache\TagAwareCacheInterface;
450451

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

454-
return 'debug';
455-
});
456+
// using autowiring to inject the cache pool
457+
public function __construct(TagAwareCacheInterface $myCachePool)
458+
{
459+
$this->myCachePool = $myCachePool;
460+
}
456461

457-
$value1 = $pool->get('item_1', function (ItemInterface $item) {
458-
$item->tag('foo');
462+
public function someMethod()
463+
{
464+
$value0 = $this->myCachePool->get('item_0', function (ItemInterface $item) {
465+
$item->tag(['foo', 'bar']);
459466

460-
return 'debug';
461-
});
467+
return 'debug';
468+
});
462469

463-
// Remove all cache keys tagged with "bar"
464-
$pool->invalidateTags(['bar']);
470+
$value1 = $this->myCachePool->get('item_1', function (ItemInterface $item) {
471+
$item->tag('foo');
472+
473+
return 'debug';
474+
});
475+
476+
// Remove all cache keys tagged with "bar"
477+
$this->myCachePool->invalidateTags(['bar']);
478+
}
479+
}
465480

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

0 commit comments

Comments
 (0)
0