From 615c852e81561be74a8a584f391d69254de3aaf1 Mon Sep 17 00:00:00 2001 From: Sandesh S Date: Wed, 12 Nov 2025 22:32:20 +0530 Subject: [PATCH 1/2] Added an option to exclude cache type while clearing or flushing --- .../Command/AbstractCacheManageCommand.php | 25 ++++++++++++++++++- .../AbstractCacheTypeManageCommand.php | 7 ++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php index ac7e9976c5715..c01bc644d06e3 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php @@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; /** * @api @@ -20,6 +21,8 @@ abstract class AbstractCacheManageCommand extends AbstractCacheCommand */ const INPUT_KEY_TYPES = 'types'; + const EXCLUDE_KEY_TYPES = 'exclude'; + /** * {@inheritdoc} */ @@ -30,6 +33,12 @@ protected function configure() InputArgument::IS_ARRAY, 'Space-separated list of cache types or omit to apply to all cache types.' ); + $this->addOption( + self::EXCLUDE_KEY_TYPES, + 'e', + InputOption::VALUE_OPTIONAL, + 'Comma separated list of cache types to omit' + ); parent::configure(); } @@ -46,8 +55,16 @@ protected function getRequestedTypes(InputInterface $input) $requestedTypes = $input->getArgument(self::INPUT_KEY_TYPES); $requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen'); } + $excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES); if (empty($requestedTypes)) { - return $this->cacheManager->getAvailableTypes(); + $cacheTypes = $this->cacheManager->getAvailableTypes(); + if (!empty($excludeTypes)) { + foreach (explode(',', $excludeTypes) as $item) { + unset($cacheTypes[array_search($item, $cacheTypes)]); + } + $cacheTypes = array_values($cacheTypes); + } + return $cacheTypes; } else { $availableTypes = $this->cacheManager->getAvailableTypes(); $unsupportedTypes = array_diff($requestedTypes, $availableTypes); @@ -57,6 +74,12 @@ protected function getRequestedTypes(InputInterface $input) . "'." . PHP_EOL . 'Supported types: ' . join(", ", $availableTypes) ); } + if (!empty($excludeTypes)) { + foreach (explode(',', $excludeTypes) as $item) { + unset($availableTypes[array_search($item, $availableTypes)]); + } + $availableTypes = array_values($availableTypes); + } return array_values(array_intersect($availableTypes, $requestedTypes)); } } diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php index ba24dcc49b6bc..700715816e6be 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php @@ -64,6 +64,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->performAction($types); $output->writeln($this->getDisplayMessage()); $output->writeln(join(PHP_EOL, $types)); + $excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES); + if (!empty($excludeTypes)) { + $output->writeln('Excluded Cache Type'); + foreach (explode(',', $excludeTypes) as $type) { + $output->writeln($type); + } + } return Cli::RETURN_SUCCESS; } From 41c2537a860062482f0f2ffc63a69d9a8187075a Mon Sep 17 00:00:00 2001 From: Sandesh S Date: Thu, 13 Nov 2025 07:30:02 +0530 Subject: [PATCH 2/2] fixed static issues --- .../Console/Command/AbstractCacheManageCommand.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php index c01bc644d06e3..86762afa51444 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php @@ -10,21 +10,17 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -/** - * @api - * @since 100.0.2 - */ abstract class AbstractCacheManageCommand extends AbstractCacheCommand { /** * Input argument types */ - const INPUT_KEY_TYPES = 'types'; + public const INPUT_KEY_TYPES = 'types'; - const EXCLUDE_KEY_TYPES = 'exclude'; + public const EXCLUDE_KEY_TYPES = 'exclude'; /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() {