blob: 83edd7a26192243d48c51922063f29acd784c132 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<?php
declare(strict_types=1);
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand;
use InvalidArgumentException;
use LogicException;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Command to clear the query cache of the various cache drivers.
*
* @link www.doctrine-project.org
*/
class QueryCommand extends AbstractEntityManagerCommand
{
protected function configure(): void
{
$this->setName('orm:clear-cache:query')
->setDescription('Clear all query cache of the various cache drivers')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')
->setHelp('The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$em = $this->getEntityManager($input);
$cache = $em->getConfiguration()->getQueryCache();
if (! $cache) {
throw new InvalidArgumentException('No Query cache driver is configured on given EntityManager.');
}
if ($cache instanceof ApcuAdapter) {
throw new LogicException('Cannot clear APCu Cache from Console, it\'s shared in the Webserver memory and not accessible from the CLI.');
}
$ui->comment('Clearing <info>all</info> Query cache entries');
$message = $cache->clear() ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
$ui->success($message);
return 0;
}
}
|