Skip to content

Commit 131115f

Browse files
committed
feat: add command to delete memcache key
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 8689a4a commit 131115f

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

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

core/register_command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
use OC\Core\Command\Maintenance\UpdateHtaccess;
7070
use OC\Core\Command\Maintenance\UpdateTheme;
7171
use OC\Core\Command\Memcache\RedisCommand;
72+
use OC\Core\Command\Memcache\DistributedDelete;
7273
use OC\Core\Command\Memcache\DistributedGet;
7374
use OC\Core\Command\Memcache\DistributedSet;
7475
use OC\Core\Command\Memcache\RedisCommand;
@@ -248,6 +249,7 @@
248249
$application->add(Server::get(Statistics::class));
249250

250251
$application->add(Server::get(RedisCommand::class));
252+
$application->add(Server::get(DistributedDelete::class));
251253
$application->add(Server::get(DistributedGet::class));
252254
$application->add(Server::get(DistributedSet::class));
253255
} else {

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@
12931293
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => $baseDir . '/core/Command/Maintenance/RepairShareOwnership.php',
12941294
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => $baseDir . '/core/Command/Maintenance/UpdateHtaccess.php',
12951295
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => $baseDir . '/core/Command/Maintenance/UpdateTheme.php',
1296+
'OC\\Core\\Command\\Memcache\\DistributedDelete' => $baseDir . '/core/Command/Memcache/DistributedDelete.php',
12961297
'OC\\Core\\Command\\Memcache\\DistributedGet' => $baseDir . '/core/Command/Memcache/DistributedGet.php',
12971298
'OC\\Core\\Command\\Memcache\\DistributedSet' => $baseDir . '/core/Command/Memcache/DistributedSet.php',
12981299
'OC\\Core\\Command\\Memcache\\RedisCommand' => $baseDir . '/core/Command/Memcache/RedisCommand.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
13341334
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => __DIR__ . '/../../..' . '/core/Command/Maintenance/RepairShareOwnership.php',
13351335
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateHtaccess.php',
13361336
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateTheme.php',
1337+
'OC\\Core\\Command\\Memcache\\DistributedDelete' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedDelete.php',
13371338
'OC\\Core\\Command\\Memcache\\DistributedGet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedGet.php',
13381339
'OC\\Core\\Command\\Memcache\\DistributedSet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedSet.php',
13391340
'OC\\Core\\Command\\Memcache\\RedisCommand' => __DIR__ . '/../../..' . '/core/Command/Memcache/RedisCommand.php',

0 commit comments

Comments
 (0)