feat: add command to clear memcache

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/52880/head
Robin Appelman 2025-05-15 17:35:53 +07:00
parent 131115fb6a
commit b5b2eb9da7
4 changed files with 51 additions and 1 deletions

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\Memcache;
use OC\Core\Command\Base;
use OCP\ICacheFactory;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class DistributedClear extends Base {
public function __construct(
protected ICacheFactory $cacheFactory,
) {
parent::__construct();
}
protected function configure(): void {
$this
->setName('memcache:distributed:clear')
->setDescription('Clear values from the distributed memcache')
->addOption('prefix', null, InputOption::VALUE_REQUIRED, 'Only remove keys matching the prefix');
parent::configure();
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$cache = $this->cacheFactory->createDistributed();
$prefix = $input->getOption('prefix');
if ($cache->clear($prefix)) {
if ($prefix) {
$output->writeln('<info>Distributed cache matching prefix ' . $prefix . ' cleared</info>');
} else {
$output->writeln('<info>Distributed cache cleared</info>');
}
return 0;
} else {
$output->writeln('<error>Failed to clear cache</error>');
return 1;
}
}
}

@ -68,7 +68,7 @@ use OC\Core\Command\Maintenance\Repair;
use OC\Core\Command\Maintenance\RepairShareOwnership; use OC\Core\Command\Maintenance\RepairShareOwnership;
use OC\Core\Command\Maintenance\UpdateHtaccess; use OC\Core\Command\Maintenance\UpdateHtaccess;
use OC\Core\Command\Maintenance\UpdateTheme; use OC\Core\Command\Maintenance\UpdateTheme;
use OC\Core\Command\Memcache\RedisCommand; use OC\Core\Command\Memcache\DistributedClear;
use OC\Core\Command\Memcache\DistributedDelete; use OC\Core\Command\Memcache\DistributedDelete;
use OC\Core\Command\Memcache\DistributedGet; use OC\Core\Command\Memcache\DistributedGet;
use OC\Core\Command\Memcache\DistributedSet; use OC\Core\Command\Memcache\DistributedSet;
@ -249,6 +249,7 @@ if ($config->getSystemValueBool('installed', false)) {
$application->add(Server::get(Statistics::class)); $application->add(Server::get(Statistics::class));
$application->add(Server::get(RedisCommand::class)); $application->add(Server::get(RedisCommand::class));
$application->add(Server::get(DistributedClear::class));
$application->add(Server::get(DistributedDelete::class)); $application->add(Server::get(DistributedDelete::class));
$application->add(Server::get(DistributedGet::class)); $application->add(Server::get(DistributedGet::class));
$application->add(Server::get(DistributedSet::class)); $application->add(Server::get(DistributedSet::class));

@ -1293,6 +1293,7 @@ return array(
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => $baseDir . '/core/Command/Maintenance/RepairShareOwnership.php', 'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => $baseDir . '/core/Command/Maintenance/RepairShareOwnership.php',
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => $baseDir . '/core/Command/Maintenance/UpdateHtaccess.php', 'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => $baseDir . '/core/Command/Maintenance/UpdateHtaccess.php',
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => $baseDir . '/core/Command/Maintenance/UpdateTheme.php', 'OC\\Core\\Command\\Maintenance\\UpdateTheme' => $baseDir . '/core/Command/Maintenance/UpdateTheme.php',
'OC\\Core\\Command\\Memcache\\DistributedClear' => $baseDir . '/core/Command/Memcache/DistributedClear.php',
'OC\\Core\\Command\\Memcache\\DistributedDelete' => $baseDir . '/core/Command/Memcache/DistributedDelete.php', 'OC\\Core\\Command\\Memcache\\DistributedDelete' => $baseDir . '/core/Command/Memcache/DistributedDelete.php',
'OC\\Core\\Command\\Memcache\\DistributedGet' => $baseDir . '/core/Command/Memcache/DistributedGet.php', 'OC\\Core\\Command\\Memcache\\DistributedGet' => $baseDir . '/core/Command/Memcache/DistributedGet.php',
'OC\\Core\\Command\\Memcache\\DistributedSet' => $baseDir . '/core/Command/Memcache/DistributedSet.php', 'OC\\Core\\Command\\Memcache\\DistributedSet' => $baseDir . '/core/Command/Memcache/DistributedSet.php',

@ -1334,6 +1334,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => __DIR__ . '/../../..' . '/core/Command/Maintenance/RepairShareOwnership.php', 'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => __DIR__ . '/../../..' . '/core/Command/Maintenance/RepairShareOwnership.php',
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateHtaccess.php', 'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateHtaccess.php',
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateTheme.php', 'OC\\Core\\Command\\Maintenance\\UpdateTheme' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateTheme.php',
'OC\\Core\\Command\\Memcache\\DistributedClear' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedClear.php',
'OC\\Core\\Command\\Memcache\\DistributedDelete' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedDelete.php', 'OC\\Core\\Command\\Memcache\\DistributedDelete' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedDelete.php',
'OC\\Core\\Command\\Memcache\\DistributedGet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedGet.php', 'OC\\Core\\Command\\Memcache\\DistributedGet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedGet.php',
'OC\\Core\\Command\\Memcache\\DistributedSet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedSet.php', 'OC\\Core\\Command\\Memcache\\DistributedSet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedSet.php',