Skip to content

Commit ec7a2b1

Browse files
committed
bug symfony#24011 [Cache] Always require symfony/polyfill-apcu to provide APCuIterator everywhere (guillaumelecerf)
This PR was merged into the 3.3 branch. Discussion ---------- [Cache] Always require symfony/polyfill-apcu to provide APCuIterator everywhere | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT **TL;DR: when APCuIterator is not available (i.e. PHP 5.6 + APCu 4.0.7), the APC cache handling is broken.** When [the app initializes](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml#L31) one of [the APC caches](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml#L14-L28), it tries to [retrieve its namespace flag key](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Traits/ApcuTrait.php#L42). If it can't, [it clears its namespaced cache](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Traits/ApcuTrait.php#L43) and [adds its flag key back](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Traits/ApcuTrait.php#L44). But [when APCuIterator is not usable](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Traits/ApcuTrait.php#L74), **the app [flushes the whole cache each time](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Traits/ApcuTrait.php#L76)**, preventing all the APC caches to retrieve their own flag key, resulting in a **perpetual full APC cache flush**. TODO: - [x] add test => https://travis-ci.org/symfony/symfony/jobs/269383629#L3334 See symfony#24008 Commits ------- 9d44442 Always require symfony/polyfill-apcu to provide APCuIterator everywhere
2 parents 9280ca4 + 9d44442 commit ec7a2b1

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"psr/link": "^1.0",
2727
"psr/log": "~1.0",
2828
"psr/simple-cache": "^1.0",
29+
"symfony/polyfill-apcu": "~1.1",
2930
"symfony/polyfill-intl-icu": "~1.0",
3031
"symfony/polyfill-mbstring": "~1.0",
3132
"symfony/polyfill-php56": "~1.0",
@@ -96,7 +97,6 @@
9697
"predis/predis": "~1.0",
9798
"egulias/email-validator": "~1.2,>=1.2.8|~2.0",
9899
"symfony/phpunit-bridge": "~3.2",
99-
"symfony/polyfill-apcu": "~1.1",
100100
"symfony/security-acl": "~2.8|~3.0",
101101
"phpdocumentor/reflection-docblock": "^3.0|^4.0",
102102
"sensio/framework-extra-bundle": "^3.0.2"

src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ public function testVersion()
7777
$this->assertNull($item->get());
7878
}
7979

80+
public function testNamespace()
81+
{
82+
$namespace = str_replace('\\', '.', get_class($this));
83+
84+
$pool1 = new ApcuAdapter($namespace.'_1', 0, 'p1');
85+
86+
$item = $pool1->getItem('foo');
87+
$this->assertFalse($item->isHit());
88+
$this->assertTrue($pool1->save($item->set('bar')));
89+
90+
$item = $pool1->getItem('foo');
91+
$this->assertTrue($item->isHit());
92+
$this->assertSame('bar', $item->get());
93+
94+
$pool2 = new ApcuAdapter($namespace.'_2', 0, 'p1');
95+
96+
$item = $pool2->getItem('foo');
97+
$this->assertFalse($item->isHit());
98+
$this->assertNull($item->get());
99+
100+
$item = $pool1->getItem('foo');
101+
$this->assertTrue($item->isHit());
102+
$this->assertSame('bar', $item->get());
103+
}
104+
80105
public function testWithCliSapi()
81106
{
82107
try {

src/Symfony/Component/Cache/composer.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"php": "^5.5.9|>=7.0.8",
2424
"psr/cache": "~1.0",
2525
"psr/log": "~1.0",
26-
"psr/simple-cache": "^1.0"
26+
"psr/simple-cache": "^1.0",
27+
"symfony/polyfill-apcu": "~1.1"
2728
},
2829
"require-dev": {
2930
"cache/integration-tests": "dev-master",
@@ -34,9 +35,6 @@
3435
"conflict": {
3536
"symfony/var-dumper": "<3.3"
3637
},
37-
"suggest": {
38-
"symfony/polyfill-apcu": "For using ApcuAdapter on HHVM"
39-
},
4038
"autoload": {
4139
"psr-4": { "Symfony\\Component\\Cache\\": "" },
4240
"exclude-from-classmap": [

0 commit comments

Comments
 (0)