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 005e8d4

Browse filesBrowse files
[FrameworkBundle] Default to Apcu+Filesystem cache chain
1 parent 854459b commit 005e8d4
Copy full SHA for 005e8d4

File tree

10 files changed

+54
-47
lines changed
Filter options

10 files changed

+54
-47
lines changed

‎UPGRADE-3.1.md

Copy file name to clipboardExpand all lines: UPGRADE-3.1.md
+2-19Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,8 @@ FrameworkBundle
9393
cache service. If you are using `serializer.mapping.cache.apc`, use
9494
`serializer.mapping.cache.doctrine.apc` instead.
9595

96-
* The `framework.serializer.cache` option has been deprecated. Configure the
97-
`cache.serializer` service under `framework.cache.pools` instead.
98-
99-
Before:
100-
101-
```yaml
102-
framework:
103-
serializer:
104-
cache: serializer.mapping.cache.apc
105-
```
106-
107-
After:
108-
109-
```yaml
110-
framework:
111-
cache:
112-
pools:
113-
cache.serializer:
114-
adapter: cache.adapter.apcu
96+
* The `framework.serializer.cache` option has been deprecated. APCu should now
97+
be automatically used when available so you can remove this configuration key.
11598

11699
HttpKernel
117100
----------

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+2-20Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,8 @@ FrameworkBundle
8080
* The service `serializer.mapping.cache.apc` has been removed; use
8181
`serializer.mapping.cache.doctrine.apc` instead.
8282

83-
* The `framework.serializer.cache` option has been removed. Configure the
84-
`cache.serializer` service under `framework.cache.pools` instead.
85-
86-
Before:
87-
88-
```yaml
89-
framework:
90-
serializer:
91-
cache: serializer.mapping.cache.apc
92-
```
93-
94-
After:
95-
96-
```yaml
97-
framework:
98-
cache:
99-
pools:
100-
cache.serializer:
101-
adapter: cache.adapter.apcu
102-
```
83+
* The `framework.serializer.cache` option has been removed. APCu should now
84+
be automatically used when available so you can remove this configuration key.
10385

10486
HttpKernel
10587
----------

‎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
+13-2Lines changed: 13 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,17 @@
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_nonce%</argument>
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" />

‎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/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14+
use Symfony\Component\Cache\Adapter\ApcuAdapter;
15+
use Symfony\Component\Cache\Adapter\ChainAdapter;
1416
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1517
use Symfony\Component\Cache\Adapter\RedisAdapter;
1618

1719
class CachePoolsTest extends WebTestCase
1820
{
1921
public function testCachePools()
2022
{
21-
$this->doTestCachePools(array(), FilesystemAdapter::class);
23+
$this->doTestCachePools(array(), ApcuAdapter::isSupported() ? ChainAdapter::class : FilesystemAdapter::class);
2224
}
2325

2426
/**

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1Lines 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",

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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;
1819

1920
/**
@@ -67,6 +68,24 @@ function ($deferred, $namespace, &$expiredIds) {
6768
);
6869
}
6970

71+
public static function createDefault($namespace = '', $defaultLifetime = 0, $nonce = null, $directory = null, LoggerInterface $logger = null)
72+
{
73+
$fs = new FilesystemAdapter($namespace, $defaultLifetime, $directory);
74+
if (null !== $logger) {
75+
$fs->setLogger($logger);
76+
}
77+
if (!ApcuAdapter::isSupported()) {
78+
return $fs;
79+
}
80+
81+
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $nonce);
82+
if (null !== $logger) {
83+
$apcu->setLogger($logger);
84+
}
85+
86+
return new ChainAdapter(array($apcu, $fs));
87+
}
88+
7089
/**
7190
* Fetches several cache items.
7291
*

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ class ApcuAdapter extends AbstractAdapter
2121
private $nonce;
2222
private $nonceLen;
2323

24+
public static function isSupported()
25+
{
26+
return function_exists('apcu_fetch') && ini_get('apc.enabled') && !('cli' === PHP_SAPI && !ini_get('apc.enable_cli'));
27+
}
28+
2429
public function __construct($namespace = '', $defaultLifetime = 0, $nonce = null)
2530
{
26-
if (!function_exists('apcu_fetch') || !ini_get('apc.enabled') || ('cli' === PHP_SAPI && !ini_get('apc.enable_cli'))) {
31+
if (!static::isSupported()) {
2732
throw new CacheException('APCu is not enabled');
2833
}
2934
if ('cli' === PHP_SAPI) {

0 commit comments

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