Skip to content

Commit 530065b

Browse files
committed
[FrameworkBundle] Add a new ClassCache cache warmer
1 parent 6991ff6 commit 530065b

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

CacheWarmer/ClassCacheCacheWarmer.php

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+
}

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)