Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8622940

Browse filesBrowse files
[FrameworkBundle] Default to Apcu+Filesystem cache chain
1 parent b85ab60 commit 8622940
Copy full SHA for 8622940

File tree

5 files changed

+41
-6
lines changed
Filter options

5 files changed

+41
-6
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,11 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
560560
->children()
561561
->scalarNode('app')
562562
->info('App related cache pools configuration')
563-
->defaultValue('cache.adapter.filesystem')
563+
->defaultValue('cache.adapter.default')
564564
->end()
565565
->scalarNode('system')
566566
->info('System related cache pools configuration')
567-
->defaultValue('cache.adapter.filesystem')
567+
->defaultValue('cache.adapter.default')
568568
->end()
569569
->scalarNode('directory')->defaultValue('%kernel.cache_dir%/pools')->end()
570570
->scalarNode('default_doctrine_provider')->end()

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
<services>
88

9-
<service id="cache.app" parent="cache.adapter.filesystem">
9+
<service id="cache.app" parent="cache.adapter.default">
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.default">
1414
<tag name="cache.pool" />
1515
</service>
1616

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

25+
<service id="cache.adapter.default" class="Symfony\Component\Cache\Adapter\ChainAdapter" abstract="true">
26+
<factory class="Symfony\Component\Cache\Adapter\AbstractAdapter" method="createDefault" />
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>%kernel.cache_dir%/pools</argument>
32+
<argument type="service" id="logger" on-invalid="ignore" />
33+
</service>
34+
2535
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
2636
<tag name="cache.pool" clearer="cache.default_clearer" />
2737
<tag name="monolog.logger" channel="cache" />

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ protected static function getBundleDefaultConfig()
268268
),
269269
'cache' => array(
270270
'pools' => array(),
271-
'app' => 'cache.adapter.filesystem',
272-
'system' => 'cache.adapter.filesystem',
271+
'app' => 'cache.adapter.default',
272+
'system' => 'cache.adapter.default',
273273
'directory' => '%kernel.cache_dir%/pools',
274274
'default_redis_provider' => 'redis://localhost',
275275
),

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+4Lines 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;

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Log\LoggerAwareInterface;
1616
use Psr\Log\LoggerAwareTrait;
17+
use Psr\Log\LoggerInterface;
1718
use Symfony\Component\Cache\CacheItem;
19+
use Symfony\Component\Cache\Exception\CacheException;
1820

1921
/**
2022
* @author Nicolas Grekas <p@tchwork.com>
@@ -67,6 +69,25 @@ function ($deferred, $namespace, &$expiredIds) {
6769
);
6870
}
6971

72+
public static function createDefault($namespace = '', $defaultLifetime = 0, $directory = null, LoggerInterface $logger = null)
73+
{
74+
$fs = new FilesystemAdapter($namespace, $defaultLifetime, $directory);
75+
if (null !== $logger) {
76+
$fs->setLogger($logger);
77+
}
78+
79+
try {
80+
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5);
81+
if (null !== $logger) {
82+
$apcu->setLogger($logger);
83+
}
84+
85+
return new ChainAdapter(array($apcu, $fs));
86+
} catch (CacheException $e) {
87+
return $fs;
88+
}
89+
}
90+
7091
/**
7192
* Fetches several cache items.
7293
*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.