You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Command\Memcache;
  8. use OC\Core\Command\Base;
  9. use OCP\ICacheFactory;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class DistributedDelete extends Base {
  14. public function __construct(
  15. protected ICacheFactory $cacheFactory,
  16. ) {
  17. parent::__construct();
  18. }
  19. protected function configure(): void {
  20. $this
  21. ->setName('memcache:distributed:delete')
  22. ->setDescription('Delete a value in the distributed memcache')
  23. ->addArgument('key', InputArgument::REQUIRED, 'The key to delete');
  24. parent::configure();
  25. }
  26. protected function execute(InputInterface $input, OutputInterface $output): int {
  27. $cache = $this->cacheFactory->createDistributed();
  28. $key = $input->getArgument('key');
  29. if ($cache->remove($key)) {
  30. $output->writeln('<info>Distributed cache key <info>' . $key . '</info> deleted</info>');
  31. return 0;
  32. } else {
  33. $output->writeln('<error>Failed to delete cache key ' . $key . '</error>');
  34. return 1;
  35. }
  36. }
  37. }