Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit cd402cc

Browse files
committed
Add command to manually clear caches
1 parent 7a5392a commit cd402cc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Command/phpFastCacheCommand.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
namespace phpFastCache\Bundle\Command;
3+
4+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Style\SymfonyStyle;
9+
10+
class phpFastCacheCommand extends ContainerAwareCommand
11+
{
12+
protected function configure()
13+
{
14+
$this
15+
->setName('phpfastcache:clear')
16+
->setDescription('Clear phpfastcache cache')
17+
->addArgument(
18+
'driver',
19+
InputArgument::OPTIONAL,
20+
'Cache name to clear'
21+
)
22+
;
23+
}
24+
protected function execute(InputInterface $input, OutputInterface $output)
25+
{
26+
$io = new SymfonyStyle($input, $output);
27+
28+
$phpFastCache = $this->getContainer()->get('phpfastcache');
29+
$driver = $input->getArgument('driver');
30+
if($driver) {
31+
$phpFastCache->get($driver)->clear();
32+
$io->success("Cache {$driver} cleared");
33+
} else {
34+
$caches = $this->getContainer()->getParameter('phpfastcache');
35+
foreach($caches['drivers'] as $name => $parameters) {
36+
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
37+
$output->writeln("Cache {$name} cleared");
38+
}
39+
$phpFastCache->get($name)->clear();
40+
}
41+
$io->success('All caches cleared');
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)