Skip to content

Commit 1a831ec

Browse files
committed
Use RedisTagAwareAdapter when tags is true and adapter is Redis
1 parent 4170346 commit 1a831ec

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CHANGELOG
1818
* Made `BrowserKitAssertionsTrait` report the original error message in case of a failure
1919
* Added ability for `config:dump-reference` and `debug:config` to dump and debug kernel container extension configuration.
2020
* Deprecated `session.attribute_bag` service and `session.flash_bag` service.
21+
* Wire `RedisTagAwareAdapter` for pools usings tags and Redis adapter
2122

2223
5.0.0
2324
-----

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Cache\Adapter\AdapterInterface;
3131
use Symfony\Component\Cache\Adapter\ArrayAdapter;
3232
use Symfony\Component\Cache\Adapter\ChainAdapter;
33+
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
3334
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
3435
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
3536
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
@@ -1853,15 +1854,26 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
18531854
if (true !== $pool['tags'] && ($config['pools'][$pool['tags']]['tags'] ?? false)) {
18541855
$pool['tags'] = '.'.$pool['tags'].'.inner';
18551856
}
1856-
$container->register($name, TagAwareAdapter::class)
1857-
->addArgument(new Reference('.'.$name.'.inner'))
1858-
->addArgument(true !== $pool['tags'] ? new Reference($pool['tags']) : null)
1859-
->setPublic($pool['public'])
1860-
;
1857+
1858+
$isRedis = $definition instanceof ChildDefinition && 'cache.adapter.redis' === $definition->getParent();
1859+
if (true === $pool['tags'] && $isRedis) {
1860+
$definition = new Definition(RedisTagAwareAdapter::class, [null, null, 0, null]);
1861+
if (!isset($pool['provider']) || !$pool['provider']) {
1862+
$pool['provider'] = 'cache.default_redis_provider';
1863+
}
1864+
$underlyingAdapterName = $name;
1865+
} else {
1866+
$container->register($name, TagAwareAdapter::class)
1867+
->addArgument(new Reference('.'.$name.'.inner'))
1868+
->addArgument(true !== $pool['tags'] ? new Reference($pool['tags']) : null)
1869+
->setPublic($pool['public'])
1870+
;
1871+
$underlyingAdapterName = '.'.$name.'.inner';
1872+
}
18611873

18621874
$pool['name'] = $name;
18631875
$pool['public'] = false;
1864-
$name = '.'.$name.'.inner';
1876+
$name = $underlyingAdapterName;
18651877

18661878
if (!\in_array($pool['name'], ['cache.app', 'cache.system'], true)) {
18671879
$container->registerAliasForArgument($pool['name'], TagAwareCacheInterface::class);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@
3232
'redis://foo' => 'cache.adapter.redis',
3333
],
3434
],
35+
'cache.tag' => [
36+
'tags' => true,
37+
'adapter' => 'cache.adapter.apcu',
38+
],
39+
'cache.redis.foo' => [
40+
'adapter' => 'cache.adapter.redis',
41+
],
42+
'cache.redis.bar' => [
43+
'tags' => true,
44+
'adapter' => 'cache.adapter.redis',
45+
],
46+
'cache.redis.baz' => [
47+
'tags' => 'cache.adapter.redis',
48+
'adapter' => 'cache.adapter.redis',
49+
],
3550
],
3651
],
3752
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
<framework:adapter name="cache.adapter.filesystem" />
1818
<framework:adapter name="cache.adapter.redis" provider="redis://foo" />
1919
</framework:pool>
20+
<framework:pool name="cache.tag" tags="true">
21+
<framework:adapter name="cache.adapter.apcu" />
22+
</framework:pool>
23+
<framework:pool name="cache.redis.foo">
24+
<framework:adapter name="cache.adapter.redis" />
25+
</framework:pool>
26+
<framework:pool name="cache.redis.bar" tags="true">
27+
<framework:adapter name="cache.adapter.redis" />
28+
</framework:pool>
29+
<framework:pool name="cache.redis.baz" tags="cache.adapter.redis">
30+
<framework:adapter name="cache.adapter.redis" />
31+
</framework:pool>
2032
</framework:cache>
2133
</framework:config>
2234
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ framework:
2323
- cache.adapter.array
2424
- cache.adapter.filesystem
2525
- {name: cache.adapter.redis, provider: 'redis://foo'}
26+
cache.tag:
27+
tags: true
28+
adapter: cache.adapter.apcu
29+
cache.redis.foo:
30+
adapter: cache.adapter.redis
31+
cache.redis.bar:
32+
tags: true
33+
adapter: cache.adapter.redis
34+
cache.redis.baz:
35+
tags: cache.adapter.redis
36+
adapter: cache.adapter.redis

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2727
use Symfony\Component\Cache\Adapter\ProxyAdapter;
2828
use Symfony\Component\Cache\Adapter\RedisAdapter;
29+
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
30+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
2931
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
3032
use Symfony\Component\DependencyInjection\ChildDefinition;
3133
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -54,6 +56,7 @@
5456
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
5557
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
5658
use Symfony\Component\Workflow;
59+
use Symfony\Contracts\Cache\TagAwareCacheInterface;
5760

5861
abstract class FrameworkExtensionTest extends TestCase
5962
{
@@ -1282,6 +1285,28 @@ public function testCachePoolServices()
12821285
$this->assertEquals($expected, $chain->getArguments());
12831286
}
12841287

1288+
public function testCacheTagAwareAdapters(): void
1289+
{
1290+
$container = $this->createContainerFromFile('cache', [], true);
1291+
1292+
$data = [
1293+
'cacheFoo' => TagAwareAdapter::class,
1294+
'cacheTag' => TagAwareAdapter::class,
1295+
'cacheChain' => TagAwareAdapter::class,
1296+
'cacheRedisFoo' => TagAwareAdapter::class,
1297+
'cacheRedisBar' => RedisTagAwareAdapter::class,
1298+
'cacheRedisBaz' => TagAwareAdapter::class,
1299+
];
1300+
1301+
foreach ($data as $varName => $expectedAdapter) {
1302+
$aliasForArgument = $container->getAlias(sprintf('%s $%s', TagAwareCacheInterface::class, $varName));
1303+
$this->assertNotNull($aliasForArgument);
1304+
$taggableDef = $container->getDefinition((string)$aliasForArgument);
1305+
$this->assertNotNull($taggableDef);
1306+
$this->assertSame($expectedAdapter, $taggableDef->getClass());
1307+
}
1308+
}
1309+
12851310
public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebug()
12861311
{
12871312
$container = $this->createContainer(['kernel.debug' => true]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy