Skip to content

Commit bb0f780

Browse files
[5.2] Cache Command - Option to optionally remove tagged items
1 parent ce607cb commit bb0f780

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/Illuminate/Cache/Console/ClearCommand.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Cache\CacheManager;
7+
use Symfony\Component\Console\Input\InputOption;
78
use Symfony\Component\Console\Input\InputArgument;
89

910
class ClearCommand extends Command
@@ -47,17 +48,26 @@ public function __construct(CacheManager $cache)
4748
*
4849
* @return void
4950
*/
50-
public function fire()
51+
public function handle()
5152
{
52-
$storeName = $this->argument('store');
53+
$storeName = $this->hasArgument('store') ? $this->argument('store') : null;
54+
$tagsNames = $this->hasOption('tags') ? $this->option('tags') : null;
5355

54-
$this->laravel['events']->fire('cache:clearing', [$storeName]);
56+
$store = $this->cache->store($storeName);
5557

56-
$this->cache->store($storeName)->flush();
58+
$this->laravel['events']->fire('cache:clearing', [$storeName, $tagsNames]);
5759

58-
$this->laravel['events']->fire('cache:cleared', [$storeName]);
60+
if (! is_null($tagsNames)) {
61+
$store->tags(explode(',', $tagsNames))->flush();
5962

60-
$this->info('Application cache cleared!');
63+
$this->info(sprintf('Application cache tags "%s" cleared!', $tagsNames));
64+
} else {
65+
$store->flush();
66+
67+
$this->info('Application cache cleared!');
68+
}
69+
70+
$this->laravel['events']->fire('cache:cleared', [$storeName, $tagsNames]);
6171
}
6272

6373
/**
@@ -71,4 +81,16 @@ protected function getArguments()
7181
['store', InputArgument::OPTIONAL, 'The name of the store you would like to clear.'],
7282
];
7383
}
84+
85+
/**
86+
* Get the console command options.
87+
*
88+
* @return array
89+
*/
90+
protected function getOptions()
91+
{
92+
return [
93+
['tags', null, InputOption::VALUE_OPTIONAL, 'The cache tags you would like to clear.', null],
94+
];
95+
}
7496
}

0 commit comments

Comments
 (0)