Skip to content

Commit 672a961

Browse files
[FrameworkBundle] Default to Apcu+Filesystem cache chain
1 parent 82665c4 commit 672a961

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
564564
->end()
565565
->scalarNode('system')
566566
->info('System related cache pools configuration')
567-
->defaultValue('cache.adapter.filesystem')
567+
->defaultValue('cache.adapter.system')
568568
->end()
569569
->scalarNode('directory')->defaultValue('%kernel.cache_dir%/pools')->end()
570570
->scalarNode('default_doctrine_provider')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
10391039
{
10401040
$nonce = substr(str_replace('/', '-', base64_encode(md5(uniqid(mt_rand(), true), true))), 0, -2);
10411041
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $nonce);
1042+
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $nonce);
10421043
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);
10431044

10441045
foreach (array('doctrine', 'psr6', 'redis') as $name) {

Resources/config/cache.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<tag name="cache.pool" />
1111
</service>
1212

13-
<service id="cache.system" parent="cache.adapter.filesystem">
13+
<service id="cache.system" parent="cache.adapter.system">
1414
<tag name="cache.pool" />
1515
</service>
1616

@@ -22,6 +22,17 @@
2222
<tag name="cache.pool" />
2323
</service>
2424

25+
<service id="cache.adapter.system" class="Symfony\Component\Cache\Adapter\AdapterInterface" abstract="true">
26+
<factory class="Symfony\Component\Cache\Adapter\AbstractAdapter" method="createSystemCache" />
27+
<tag name="cache.pool" clearer="cache.default_clearer" />
28+
<tag name="monolog.logger" channel="cache" />
29+
<argument /> <!-- namespace -->
30+
<argument /> <!-- default lifetime -->
31+
<argument /> <!-- nonce -->
32+
<argument>%kernel.cache_dir%/pools</argument>
33+
<argument type="service" id="logger" on-invalid="ignore" />
34+
</service>
35+
2536
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
2637
<tag name="cache.pool" clearer="cache.default_clearer" />
2738
<tag name="monolog.logger" channel="cache" />

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ protected static function getBundleDefaultConfig()
269269
'cache' => array(
270270
'pools' => array(),
271271
'app' => 'cache.adapter.filesystem',
272-
'system' => 'cache.adapter.filesystem',
272+
'system' => 'cache.adapter.system',
273273
'directory' => '%kernel.cache_dir%/pools',
274274
'default_redis_provider' => 'redis://localhost',
275275
),

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
1616
use Symfony\Component\Cache\Adapter\ApcuAdapter;
17+
use Symfony\Component\Cache\Adapter\ChainAdapter;
1718
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
1819
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1920
use Symfony\Component\Cache\Adapter\ProxyAdapter;
@@ -728,6 +729,9 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
728729
$this->assertSame(DoctrineAdapter::class, $parentDefinition->getClass());
729730
break;
730731
case 'cache.app':
732+
if (ChainAdapter::class === $parentDefinition->getClass()) {
733+
break;
734+
}
731735
case 'cache.adapter.filesystem':
732736
$this->assertSame(FilesystemAdapter::class, $parentDefinition->getClass());
733737
break;

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"phpdocumentor/reflection-docblock": "<3.0"
5959
},
6060
"suggest": {
61+
"ext-apcu": "For best performance of the system caches",
6162
"symfony/console": "For using the console commands",
6263
"symfony/form": "For using forms",
6364
"symfony/serializer": "For using the serializer service",

0 commit comments

Comments
 (0)