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 @@ -439,21 +439,36 @@ use cache tags. One or more tags could be added to the cache item. All items wit
439
439
the same key could be invalidate with one function call::
440
440
441
441
use Symfony\Contracts\Cache\ItemInterface;
442
+ use Symfony\Contracts\Cache\TagAwareCacheInterface;
442
443
443
- $value0 = $pool->get('item_0', function (ItemInterface $item) {
444
- $item->tag(['foo', 'bar']);
444
+ class SomeClass
445
+ {
446
+ private $myCachePool;
445
447
446
- return 'debug';
447
- });
448
+ // using autowiring to inject the cache pool
449
+ public function __construct(TagAwareCacheInterface $myCachePool)
450
+ {
451
+ $this->myCachePool = $myCachePool;
452
+ }
448
453
449
- $value1 = $pool->get('item_1', function (ItemInterface $item) {
450
- $item->tag('foo');
454
+ public function someMethod()
455
+ {
456
+ $value0 = $this->myCachePool->get('item_0', function (ItemInterface $item) {
457
+ $item->tag(['foo', 'bar']);
451
458
452
- return 'debug';
453
- });
459
+ return 'debug';
460
+ });
454
461
455
- // Remove all cache keys tagged with "bar"
456
- $pool->invalidateTags(['bar']);
462
+ $value1 = $this->myCachePool->get('item_1', function (ItemInterface $item) {
463
+ $item->tag('foo');
464
+
465
+ return 'debug';
466
+ });
467
+
468
+ // Remove all cache keys tagged with "bar"
469
+ $this->myCachePool->invalidateTags(['bar']);
470
+ }
471
+ }
457
472
458
473
The cache adapter needs to implement :class: `Symfony\\ Contracts\\ Cache\\ TagAwareCacheInterface` `
459
474
to enable this feature. This could be added by using the following configuration.
You can’t perform that action at this time.
0 commit comments