CacheCommand.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Base\Services\CacheTrait;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Cache;
  6. class CacheCommand extends Command
  7. {
  8. use CacheTrait;
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'cache {name}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '清除缓存';
  21. /**
  22. * Create a new command instance.
  23. *
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $name = $this->argument('name');
  37. if ($name=='flush') {
  38. Cache::flush();
  39. echo 'cache flush success.';
  40. } elseif (!empty($name)) {
  41. if ($name == 'ws:fd') {
  42. $withPrefix = false;
  43. } else {
  44. $withPrefix = true;
  45. }
  46. $this->removeByKey($name, $withPrefix);
  47. echo 'cache keys:'.$name.' remove successful';
  48. }
  49. }
  50. }