Permalink
Browse files

Update clearAll method whith cache type opcode

Simplify command
  • Loading branch information...
1 parent 52550c4 commit 7d80006e7cc3bda935919ae83fc3550388563b65 @kelu95 committed Jun 17, 2011
Showing with 22 additions and 44 deletions.
  1. +19 −41 Command/ClearCommand.php
  2. +3 −3 Controller/Cache.php
View
@@ -27,61 +27,39 @@ class ClearCommand extends BaseCommand
protected function configure()
{
$this
- ->setName('apc:clear')
- ->setDescription('Clear all APC cache user or filehits')
- ->setDefinition(array(
- new InputArgument('type', InputArgument::REQUIRED, 'The cache type (user or file)')
- ))
- ->setHelp(<<<EOT
-The <info>apc:clear</info> command that clear all APC cache :
-<info>php app/console apc:clear type</info>
-The type argument is required
-EOT
- );
+ ->setDefinition(array())
+ ->setDescription('Clear all APC cache user or opcode')
+ ->addOption('opcode', null, InputOption::VALUE_NONE, 'Clear opcode cache')
+ ->addOption('user', null, InputOption::VALUE_NONE, 'Clear user cache')
+ ->setName('apc:clear');
}
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $logger = $this->container->get('logger'); //get logger service
+ if(!$input->getOption('user') && !$input->getOption('opcode')){
+ $output->writeln('Error : Cache type option must be --user or --opcode');
+ return;
+ }
+
+ //Define cache type from passed option
+ if($input->getOption('user')) $cache_type="user";
+ else if($input->getOption('opcode')) $cache_type="opcode";
- $cache_type=''; //empty for filehits
- if($input->getArgument('type')=='user') $cache_type='user';
-
$cache = $this->container->get('apc_cache'); //get apc_cache service
- $cache->clearAll($cache_type);
+ $cache->clearAll($cache_type); //clear
- $output_str='APC clear all cache '.$input->getArgument('type').' from HOST : '.gethostname();
+ //output + logger
+ $output_str='APC clear all cache '.$cache_type.' from HOST : '.gethostname();
+ $logger = $this->container->get('logger'); //get logger service
$logger->info($output_str);
+
$output->writeln($output_str);
}
- /**
- * @see Command
- */
- protected function interact(InputInterface $input, OutputInterface $output)
- {
- $logger = $this->container->get('logger');
-
- if (!$input->getArgument('type')) {
- $type = $this->getHelper('dialog')->askAndValidate(
- $output,
- 'Please specify the cache to clear [user or file]:',
- function($type)
- {
- if (empty($type) || ($type!='user' && $type!='file')) {
- throw new \Exception('Cache type must be user our file');
- }
-
- return $type;
- }
- );
- $input->setArgument('type', $type);
- }
- }
-
+
}
View
@@ -102,15 +102,15 @@ public function delete($name)
/**
* Delete cache user or filehits
*
- * @param string $cache_type user or empty
+ * @param string $cache_type user or opcode
*/
- public function clearAll($cache_type='')
+ public function clearAll($cache_type='user')
{
apc_clear_cache($cache_type);
}
/**
- * Get apc cache infos by type (user or filehits)
+ * Get apc cache infos by type
*
* @param string $cache_type user or empty
* @return array

0 comments on commit 7d80006

Please sign in to comment.