Skip to content

Commit 0706cb4

Browse files
committed
Make sure you can change tags with a constructor argument
1 parent c94676a commit 0706cb4

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/Cache/DoctrineTaggingCachePool.php renamed to src/Cache/FixedTaggingCachePool.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,87 +21,94 @@
2121
*
2222
* @author Tobias Nyholm <[email protected]>
2323
*/
24-
class DoctrineTaggingCachePool implements CacheItemPoolInterface
24+
class FixedTaggingCachePool implements CacheItemPoolInterface
2525
{
2626
/**
2727
* @type CacheItemPoolInterface|TaggablePoolInterface
2828
*/
2929
private $cache;
3030

31+
/**
32+
* @type array
33+
*/
34+
private $tags;
35+
3136
/**
3237
* @param TaggablePoolInterface $cache
38+
* @param array $tags
3339
*/
34-
public function __construct(TaggablePoolInterface $cache)
40+
public function __construct(TaggablePoolInterface $cache, array $tags)
3541
{
3642
$this->cache = $cache;
43+
$this->tags = $tags;
3744
}
3845

3946
/**
40-
* @{@inheritdoc}
47+
* {@inheritdoc}
4148
*/
4249
public function getItem($key)
4350
{
44-
return $this->cache->getItem($key, ['doctrine']);
51+
return $this->cache->getItem($key, $this->tags);
4552
}
4653

4754
/**
48-
* @{@inheritdoc}
55+
* {@inheritdoc}
4956
*/
5057
public function getItems(array $keys = [])
5158
{
52-
return $this->cache->getItems($keys, ['doctrine']);
59+
return $this->cache->getItems($keys, $this->tags);
5360
}
5461

5562
/**
56-
* @{@inheritdoc}
63+
* {@inheritdoc}
5764
*/
5865
public function hasItem($key)
5966
{
60-
return $this->cache->hasItem($key, ['doctrine']);
67+
return $this->cache->hasItem($key, $this->tags);
6168
}
6269

6370
/**
64-
* @{@inheritdoc}
71+
* {@inheritdoc}
6572
*/
6673
public function clear()
6774
{
68-
return $this->cache->clear(['doctrine']);
75+
return $this->cache->clear($this->tags);
6976
}
7077

7178
/**
72-
* @{@inheritdoc}
79+
* {@inheritdoc}
7380
*/
7481
public function deleteItem($key)
7582
{
76-
return $this->cache->deleteItem($key, ['doctrine']);
83+
return $this->cache->deleteItem($key, $this->tags);
7784
}
7885

7986
/**
80-
* @{@inheritdoc}
87+
* {@inheritdoc}
8188
*/
8289
public function deleteItems(array $keys)
8390
{
84-
return $this->cache->deleteItems($keys, ['doctrine']);
91+
return $this->cache->deleteItems($keys, $this->tags);
8592
}
8693

8794
/**
88-
* @{@inheritdoc}
95+
* {@inheritdoc}
8996
*/
9097
public function save(CacheItemInterface $item)
9198
{
9299
return $this->cache->save($item);
93100
}
94101

95102
/**
96-
* @{@inheritdoc}
103+
* {@inheritdoc}
97104
*/
98105
public function saveDeferred(CacheItemInterface $item)
99106
{
100107
return $this->cache->saveDeferred($item);
101108
}
102109

103110
/**
104-
* @{@inheritdoc}
111+
* {@inheritdoc}
105112
*/
106113
public function commit()
107114
{

src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Cache\CacheBundle\DependencyInjection\Compiler;
1313

1414
use Cache\Bridge\DoctrineCacheBridge;
15-
use Cache\CacheBundle\Cache\DoctrineTaggingCachePool;
15+
use Cache\CacheBundle\Cache\FixedTaggingCachePool;
1616
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

@@ -106,8 +106,9 @@ public function getPoolReferenceForBridge($bridgeServiceId, $cacheData, $tagging
106106
}
107107

108108
$taggingServiceId = $bridgeServiceId.'.tagging';
109-
$taggingDef = $this->container->register($taggingServiceId, DoctrineTaggingCachePool::class);
109+
$taggingDef = $this->container->register($taggingServiceId, FixedTaggingCachePool::class);
110110
$taggingDef->addArgument(new Reference($cacheData['service_id']))
111+
->addArgument(['doctrine'])
111112
->setPublic(false);
112113

113114
return $taggingServiceId;

0 commit comments

Comments
 (0)