Passed
Pull Request — master (#2689)
by Antoine
05:28
created

CachePoolClearerCacheWarmer::warmUp()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[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
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\CacheWarmer;
15
16
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
17
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
18
19
/**
20
 * Clears the cache pools when warming up the cache.
21
 *
22
 * Do not use in production!
23
 *
24
 * @internal
25
 */
26
final class CachePoolClearerCacheWarmer implements CacheWarmerInterface
27
{
28
    private $poolClearer;
29
    private $pools;
30
31
    public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
32
    {
33
        $this->poolClearer = $poolClearer;
34
        $this->pools = $pools;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function warmUp($cacheDirectory): void
41
    {
42
        foreach ($this->pools as $pool) {
43
            if ($this->poolClearer->hasPool($pool)) {
44
                $this->poolClearer->clearPool($pool);
45
            }
46
        }
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function isOptional(): bool
53
    {
54
        // optional cache warmers are not run when handling the request
55
        return false;
56
    }
57
}
58