ForgetCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Illuminate\Cache\Console;
  3. use Illuminate\Cache\CacheManager;
  4. use Illuminate\Console\Command;
  5. use Symfony\Component\Console\Attribute\AsCommand;
  6. #[AsCommand(name: 'cache:forget')]
  7. class ForgetCommand extends Command
  8. {
  9. /**
  10. * The console command name.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'cache:forget {key : The key to remove} {store? : The store to remove the key from}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Remove an item from the cache';
  21. /**
  22. * The cache manager instance.
  23. *
  24. * @var \Illuminate\Cache\CacheManager
  25. */
  26. protected $cache;
  27. /**
  28. * Create a new cache clear command instance.
  29. *
  30. * @param \Illuminate\Cache\CacheManager $cache
  31. * @return void
  32. */
  33. public function __construct(CacheManager $cache)
  34. {
  35. parent::__construct();
  36. $this->cache = $cache;
  37. }
  38. /**
  39. * Execute the console command.
  40. *
  41. * @return void
  42. */
  43. public function handle()
  44. {
  45. $this->cache->store($this->argument('store'))->forget(
  46. $this->argument('key')
  47. );
  48. $this->components->info('The ['.$this->argument('key').'] key has been removed from the cache.');
  49. }
  50. }