Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2e0d46d

Browse filesBrowse files
committed
feat: add command to clear memcache
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 04c5e9e commit 2e0d46d
Copy full SHA for 2e0d46d

File tree

4 files changed

+51
-1
lines changed
Filter options

4 files changed

+51
-1
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
class DistributedClear 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:clear')
27+
->setDescription('Clear values from the distributed memcache')
28+
->addOption('prefix', null, InputOption::VALUE_REQUIRED, 'Only remove keys matching the prefix');
29+
parent::configure();
30+
}
31+
32+
protected function execute(InputInterface $input, OutputInterface $output): int {
33+
$cache = $this->cacheFactory->createDistributed();
34+
$prefix = $input->getOption('prefix');
35+
if ($cache->clear($prefix)) {
36+
if ($prefix) {
37+
$output->writeln('Distributed cache matching prefix ' . $prefix . ' cleared</info>');
38+
} else {
39+
$output->writeln('Distributed cache cleared</info>');
40+
}
41+
return 0;
42+
} else {
43+
$output->writeln('<error>Failed to clear cache</error>');
44+
return 1;
45+
}
46+
}
47+
}

‎core/register_command.php

Copy file name to clipboardExpand all lines: core/register_command.php
+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
use OC\Core\Command\Maintenance\RepairShareOwnership;
6969
use OC\Core\Command\Maintenance\UpdateHtaccess;
7070
use OC\Core\Command\Maintenance\UpdateTheme;
71-
use OC\Core\Command\Memcache\RedisCommand;
71+
use OC\Core\Command\Memcache\DistributedClear;
7272
use OC\Core\Command\Memcache\DistributedDelete;
7373
use OC\Core\Command\Memcache\DistributedGet;
7474
use OC\Core\Command\Memcache\DistributedSet;
@@ -247,6 +247,7 @@
247247
$application->add(Server::get(Statistics::class));
248248

249249
$application->add(Server::get(RedisCommand::class));
250+
$application->add(Server::get(DistributedClear::class));
250251
$application->add(Server::get(DistributedDelete::class));
251252
$application->add(Server::get(DistributedGet::class));
252253
$application->add(Server::get(DistributedSet::class));

‎lib/composer/composer/autoload_classmap.php

Copy file name to clipboardExpand all lines: lib/composer/composer/autoload_classmap.php
+1
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@
12871287
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => $baseDir . '/core/Command/Maintenance/RepairShareOwnership.php',
12881288
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => $baseDir . '/core/Command/Maintenance/UpdateHtaccess.php',
12891289
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => $baseDir . '/core/Command/Maintenance/UpdateTheme.php',
1290+
'OC\\Core\\Command\\Memcache\\DistributedClear' => $baseDir . '/core/Command/Memcache/DistributedClear.php',
12901291
'OC\\Core\\Command\\Memcache\\DistributedDelete' => $baseDir . '/core/Command/Memcache/DistributedDelete.php',
12911292
'OC\\Core\\Command\\Memcache\\DistributedGet' => $baseDir . '/core/Command/Memcache/DistributedGet.php',
12921293
'OC\\Core\\Command\\Memcache\\DistributedSet' => $baseDir . '/core/Command/Memcache/DistributedSet.php',

‎lib/composer/composer/autoload_static.php

Copy file name to clipboardExpand all lines: lib/composer/composer/autoload_static.php
+1
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
13281328
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => __DIR__ . '/../../..' . '/core/Command/Maintenance/RepairShareOwnership.php',
13291329
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateHtaccess.php',
13301330
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateTheme.php',
1331+
'OC\\Core\\Command\\Memcache\\DistributedClear' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedClear.php',
13311332
'OC\\Core\\Command\\Memcache\\DistributedDelete' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedDelete.php',
13321333
'OC\\Core\\Command\\Memcache\\DistributedGet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedGet.php',
13331334
'OC\\Core\\Command\\Memcache\\DistributedSet' => __DIR__ . '/../../..' . '/core/Command/Memcache/DistributedSet.php',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.