Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c857ba5

Browse files
[FrameworkBundle] Don't populate fallback cache on warmup
1 parent bc45a0e commit c857ba5

10 files changed

+34
-100
lines changed

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

14-
use Psr\Cache\CacheItemPoolInterface;
15-
use Symfony\Component\Cache\Adapter\AdapterInterface;
1614
use Symfony\Component\Cache\Adapter\ArrayAdapter;
15+
use Symfony\Component\Cache\Adapter\NullAdapter;
1716
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
18-
use Symfony\Component\Cache\Adapter\ProxyAdapter;
1917
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
2018

2119
/**
@@ -24,19 +22,13 @@
2422
abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface
2523
{
2624
private $phpArrayFile;
27-
private $fallbackPool;
2825

2926
/**
30-
* @param string $phpArrayFile The PHP file where metadata are cached
31-
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
27+
* @param string $phpArrayFile The PHP file where metadata are cached
3228
*/
33-
public function __construct(string $phpArrayFile, CacheItemPoolInterface $fallbackPool)
29+
public function __construct(string $phpArrayFile)
3430
{
3531
$this->phpArrayFile = $phpArrayFile;
36-
if (!$fallbackPool instanceof AdapterInterface) {
37-
$fallbackPool = new ProxyAdapter($fallbackPool);
38-
}
39-
$this->fallbackPool = $fallbackPool;
4032
}
4133

4234
/**
@@ -68,13 +60,7 @@ public function warmUp($cacheDir)
6860
// so here we un-serialize the values first
6961
$values = array_map(function ($val) { return null !== $val ? unserialize($val) : null; }, $arrayAdapter->getValues());
7062

71-
$this->warmUpPhpArrayAdapter(new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool), $values);
72-
73-
foreach ($values as $k => $v) {
74-
$item = $this->fallbackPool->getItem($k);
75-
$this->fallbackPool->saveDeferred($item->set($v));
76-
}
77-
$this->fallbackPool->commit();
63+
$this->warmUpPhpArrayAdapter(new PhpArrayAdapter($this->phpArrayFile, new NullAdapter()), $values);
7864
}
7965

8066
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
3131
private $debug;
3232

3333
/**
34-
* @param Reader $annotationReader
35-
* @param string $phpArrayFile The PHP file where annotations are cached
36-
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered annotations are cached
34+
* @param string $phpArrayFile The PHP file where annotations are cached
35+
* @param string $excludeRegexp
36+
* @param bool $debug
3737
*/
38-
public function __construct(Reader $annotationReader, string $phpArrayFile, CacheItemPoolInterface $fallbackPool, string $excludeRegexp = null, bool $debug = false)
38+
public function __construct(Reader $annotationReader, string $phpArrayFile, $excludeRegexp = null, $debug = false)
3939
{
40-
parent::__construct($phpArrayFile, $fallbackPool);
40+
if ($excludeRegexp instanceof CacheItemPoolInterface) {
41+
@trigger_error(sprintf('The CacheItemPoolInterface $fallbackPool argument of "%s()" is deprecated since Symfony 4.2, you should not pass it anymore.', __METHOD__), E_USER_DEPRECATED);
42+
$excludeRegexp = $debug;
43+
$debug = 4 < \func_num_args() && \func_get_arg(4);
44+
}
45+
parent::__construct($phpArrayFile);
4146
$this->annotationReader = $annotationReader;
4247
$this->excludeRegexp = $excludeRegexp;
4348
$this->debug = $debug;

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerializerCacheWarmer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ class SerializerCacheWarmer extends AbstractPhpFileCacheWarmer
3131
private $loaders;
3232

3333
/**
34-
* @param LoaderInterface[] $loaders The serializer metadata loaders
35-
* @param string $phpArrayFile The PHP file where metadata are cached
36-
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
34+
* @param LoaderInterface[] $loaders The serializer metadata loaders
35+
* @param string $phpArrayFile The PHP file where metadata are cached
3736
*/
38-
public function __construct(array $loaders, string $phpArrayFile, CacheItemPoolInterface $fallbackPool)
37+
public function __construct(array $loaders, string $phpArrayFile)
3938
{
40-
parent::__construct($phpArrayFile, $fallbackPool);
39+
if (2 < \func_num_args() && \func_get_arg(2) instanceof CacheItemPoolInterface) {
40+
@trigger_error(sprintf('The CacheItemPoolInterface $fallbackPool argument of "%s()" is deprecated since Symfony 4.2, you should not pass it anymore.', __METHOD__), E_USER_DEPRECATED);
41+
}
42+
parent::__construct($phpArrayFile);
4143
$this->loaders = $loaders;
4244
}
4345

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ class ValidatorCacheWarmer extends AbstractPhpFileCacheWarmer
3333
private $validatorBuilder;
3434

3535
/**
36-
* @param ValidatorBuilderInterface $validatorBuilder
37-
* @param string $phpArrayFile The PHP file where metadata are cached
38-
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
36+
* @param string $phpArrayFile The PHP file where metadata are cached
3937
*/
40-
public function __construct(ValidatorBuilderInterface $validatorBuilder, string $phpArrayFile, CacheItemPoolInterface $fallbackPool)
38+
public function __construct(ValidatorBuilderInterface $validatorBuilder, string $phpArrayFile)
4139
{
42-
parent::__construct($phpArrayFile, $fallbackPool);
40+
if (2 < \func_num_args() && \func_get_arg(2) instanceof CacheItemPoolInterface) {
41+
@trigger_error(sprintf('The CacheItemPoolInterface $fallbackPool argument of "%s()" is deprecated since Symfony 4.2, you should not pass it anymore.', __METHOD__), E_USER_DEPRECATED);
42+
}
43+
parent::__construct($phpArrayFile);
4344
$this->validatorBuilder = $validatorBuilder;
4445
}
4546

src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
<service id="annotations.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer">
3737
<argument type="service" id="annotations.reader" />
3838
<argument>%kernel.cache_dir%/annotations.php</argument>
39-
<argument type="service" id="cache.annotations" />
4039
<argument>#^Symfony\\(?:Component\\HttpKernel\\|Bundle\\FrameworkBundle\\Controller\\(?!AbstractController$|Controller$))#</argument>
4140
<argument>%kernel.debug%</argument>
4241
</service>

src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
<service id="serializer.mapping.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer">
9191
<argument type="collection" /><!-- Loaders injected by the extension -->
9292
<argument>%serializer.mapping.cache.file%</argument>
93-
<argument type="service" id="cache.serializer" />
9493
<tag name="kernel.cache_warmer" />
9594
</service>
9695

src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<service id="validator.mapping.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\ValidatorCacheWarmer">
3636
<argument type="service" id="validator.builder" />
3737
<argument>%validator.mapping.cache.file%</argument>
38-
<argument type="service" id="cache.validator" />
3938
<tag name="kernel.cache_warmer" />
4039
</service>
4140

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Doctrine\Common\Annotations\Reader;
88
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
99
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
10-
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1110
use Symfony\Component\Cache\Adapter\NullAdapter;
1211
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1312
use Symfony\Component\Cache\DoctrineProvider;
@@ -37,13 +36,7 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
3736
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export(array(__CLASS__), true)));
3837
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
3938
$reader = new AnnotationReader();
40-
$fallbackPool = new ArrayAdapter();
41-
$warmer = new AnnotationsCacheWarmer(
42-
$reader,
43-
$cacheFile,
44-
$fallbackPool,
45-
null
46-
);
39+
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile);
4740
$warmer->warmUp($this->cacheDir);
4841
$this->assertFileExists($cacheFile);
4942

@@ -63,14 +56,7 @@ public function testAnnotationsCacheWarmerWithDebugEnabled()
6356
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export(array(__CLASS__), true)));
6457
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
6558
$reader = new AnnotationReader();
66-
$fallbackPool = new ArrayAdapter();
67-
$warmer = new AnnotationsCacheWarmer(
68-
$reader,
69-
$cacheFile,
70-
$fallbackPool,
71-
null,
72-
true
73-
);
59+
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true);
7460
$warmer->warmUp($this->cacheDir);
7561
$this->assertFileExists($cacheFile);
7662
// Assert cache is valid

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/SerializerCacheWarmerTest.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer;
1515
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
16-
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1716
use Symfony\Component\Cache\Adapter\NullAdapter;
1817
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1918
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
@@ -36,9 +35,7 @@ public function testWarmUp()
3635
$file = sys_get_temp_dir().'/cache-serializer.php';
3736
@unlink($file);
3837

39-
$fallbackPool = new ArrayAdapter();
40-
41-
$warmer = new SerializerCacheWarmer($loaders, $file, $fallbackPool);
38+
$warmer = new SerializerCacheWarmer($loaders, $file);
4239
$warmer->warmUp(\dirname($file));
4340

4441
$this->assertFileExists($file);
@@ -47,13 +44,6 @@ public function testWarmUp()
4744

4845
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
4946
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
50-
51-
$values = $fallbackPool->getValues();
52-
53-
$this->assertInternalType('array', $values);
54-
$this->assertCount(2, $values);
55-
$this->assertArrayHasKey('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person', $values);
56-
$this->assertArrayHasKey('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author', $values);
5747
}
5848

5949
public function testWarmUpWithoutLoader()
@@ -65,16 +55,9 @@ public function testWarmUpWithoutLoader()
6555
$file = sys_get_temp_dir().'/cache-serializer-without-loader.php';
6656
@unlink($file);
6757

68-
$fallbackPool = new ArrayAdapter();
69-
70-
$warmer = new SerializerCacheWarmer(array(), $file, $fallbackPool);
58+
$warmer = new SerializerCacheWarmer(array(), $file);
7159
$warmer->warmUp(\dirname($file));
7260

7361
$this->assertFileExists($file);
74-
75-
$values = $fallbackPool->getValues();
76-
77-
$this->assertInternalType('array', $values);
78-
$this->assertCount(0, $values);
7962
}
8063
}

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\CacheWarmer\ValidatorCacheWarmer;
1515
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
16-
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1716
use Symfony\Component\Cache\Adapter\NullAdapter;
1817
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1918
use Symfony\Component\Validator\Mapping\ClassMetadata;
@@ -32,9 +31,7 @@ public function testWarmUp()
3231
$file = sys_get_temp_dir().'/cache-validator.php';
3332
@unlink($file);
3433

35-
$fallbackPool = new ArrayAdapter();
36-
37-
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
34+
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file);
3835
$warmer->warmUp(\dirname($file));
3936

4037
$this->assertFileExists($file);
@@ -43,13 +40,6 @@ public function testWarmUp()
4340

4441
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person')->isHit());
4542
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author')->isHit());
46-
47-
$values = $fallbackPool->getValues();
48-
49-
$this->assertInternalType('array', $values);
50-
$this->assertCount(2, $values);
51-
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person', $values);
52-
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author', $values);
5343
}
5444

5545
public function testWarmUpWithAnnotations()
@@ -61,9 +51,7 @@ public function testWarmUpWithAnnotations()
6151
$file = sys_get_temp_dir().'/cache-validator-with-annotations.php';
6252
@unlink($file);
6353

64-
$fallbackPool = new ArrayAdapter();
65-
66-
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
54+
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file);
6755
$warmer->warmUp(\dirname($file));
6856

6957
$this->assertFileExists($file);
@@ -74,13 +62,6 @@ public function testWarmUpWithAnnotations()
7462
$this->assertTrue($item->isHit());
7563

7664
$this->assertInstanceOf(ClassMetadata::class, $item->get());
77-
78-
$values = $fallbackPool->getValues();
79-
80-
$this->assertInternalType('array', $values);
81-
$this->assertCount(2, $values);
82-
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
83-
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);
8465
}
8566

8667
public function testWarmUpWithoutLoader()
@@ -90,16 +71,9 @@ public function testWarmUpWithoutLoader()
9071
$file = sys_get_temp_dir().'/cache-validator-without-loaders.php';
9172
@unlink($file);
9273

93-
$fallbackPool = new ArrayAdapter();
94-
95-
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
74+
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file);
9675
$warmer->warmUp(\dirname($file));
9776

9877
$this->assertFileExists($file);
99-
100-
$values = $fallbackPool->getValues();
101-
102-
$this->assertInternalType('array', $values);
103-
$this->assertCount(0, $values);
10478
}
10579
}

0 commit comments

Comments
 (0)