File tree Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -447,21 +447,36 @@ use cache tags. One or more tags could be added to the cache item. All items wit
447447the 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
466481The cache adapter needs to implement :class: `Symfony\\ Contracts\\ Cache\\ TagAwareCacheInterface` `
467482to enable this feature. This could be added by using the following configuration.
You can’t perform that action at this time.
0 commit comments