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

Skip to content

Commit 43026f9

Browse files
committed
feature #16263 [FrameworkBundle] Add a new ClassCache cache warmer (tucksaun)
This PR was merged into the 2.8 branch. Discussion ---------- [FrameworkBundle] Add a new ClassCache cache warmer | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This new cache warmer allows to remove the known slowness of the first hit of a Symfony application (even when cache has been warmed up). This also allows to make a Symfony application runnable on a read-only filesystem (like in a Docker container for example) Commits ------- b570d6c [FrameworkBundle] Add a new ClassCache cache warmer
2 parents b9c0fe4 + b570d6c commit 43026f9

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
13+
14+
use Symfony\Component\ClassLoader\ClassCollectionLoader;
15+
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
16+
17+
/**
18+
* Generates the Class Cache (classes.php) file.
19+
*
20+
* @author Tugdual Saunier <[email protected]>
21+
*/
22+
class ClassCacheCacheWarmer implements CacheWarmerInterface
23+
{
24+
/**
25+
* Warms up the cache.
26+
*
27+
* @param string $cacheDir The cache directory
28+
*/
29+
public function warmUp($cacheDir)
30+
{
31+
$classmap = $cacheDir.'/classes.map';
32+
33+
if (!is_file($classmap)) {
34+
return;
35+
}
36+
37+
ClassCollectionLoader::load(include($classmap), $cacheDir, 'classes', false);
38+
}
39+
40+
/**
41+
* Checks whether this warmer is optional or not.
42+
*
43+
* @return bool always true
44+
*/
45+
public function isOptional()
46+
{
47+
return true;
48+
}
49+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<argument type="collection" />
3535
</service>
3636

37+
<service id="kernel.class_cache.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassCacheCacheWarmer">
38+
<tag name="kernel.cache_warmer" />
39+
</service>
40+
3741
<service id="cache_clearer" class="%cache_clearer.class%">
3842
<argument type="collection" />
3943
</service>

0 commit comments

Comments
 (0)