Skip to content

Commit 69dc179

Browse files
committed
cache purge
1 parent 79c6045 commit 69dc179

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

src/Core/Command/CachePurgeCommand.php

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Windwalker\Console\CommandWrapper;
1313
use Windwalker\Console\CompletionContext;
1414
use Windwalker\Console\CompletionHandlerInterface;
15+
use Windwalker\Console\Input\InputOption;
1516
use Windwalker\Console\IOInterface;
1617
use Windwalker\Core\Application\ApplicationInterface;
1718
use Windwalker\DI\Exception\DependencyResolutionException;
@@ -38,6 +39,20 @@ public function configure(Command $command): void
3839
InputArgument::IS_ARRAY,
3940
'Clear these profiles, if not provided, will clear all profiles.'
4041
);
42+
43+
$command->addOption(
44+
'group',
45+
'g',
46+
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
47+
'Clear these groups, default is empty group.'
48+
);
49+
50+
$command->addOption(
51+
'tag',
52+
't',
53+
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
54+
'Invalidate tags, if not provided, will clear all tags.'
55+
);
4156
}
4257

4358
/**
@@ -68,9 +83,52 @@ protected function clearCacheProfile(string $profile, IOInterface $io): void
6883
{
6984
$cache = $this->app->retrieve(CachePool::class, tag: $profile);
7085

71-
$cache->clear();
86+
$groups = (array) $io->getOption('group');
87+
$tags = (array) $io->getOption('tag');
88+
89+
if ($groups === []) {
90+
$caches = ['__main__' => $cache];
91+
$hasGroups = false;
92+
} else {
93+
$caches = [];
94+
$hasGroups = true;
95+
96+
foreach ($groups as $group) {
97+
if (!$cache->isGroupSupported()) {
98+
continue;
99+
}
100+
101+
$caches[$group] = $cache->withGroup($group);
102+
}
103+
}
104+
105+
if ($caches !== []) {
106+
foreach ($caches as $group => $cache) {
107+
if ($tags === []) {
108+
$cache->clear();
109+
110+
$io->writeln(
111+
sprintf(
112+
'[Clear] <info>%s%s</info>',
113+
$profile,
114+
$hasGroups ? ':' . $group : ''
115+
)
116+
);
117+
} else {
118+
$cache->invalidateTags(...$tags);
119+
120+
$io->writeln(
121+
sprintf(
122+
'[Invalidate] <info>%s%s</info> - Tags: <comment>%s</comment>',
123+
$profile,
124+
$hasGroups ? ':' . $group : '',
125+
implode(',', $tags)
126+
)
127+
);
128+
}
129+
}
130+
}
72131

73-
$io->writeln(sprintf('[Clear] <info>%s</info>', $profile));
74132
}
75133

76134
/**

src/Core/Edge/ComponentFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function find(): array
3636
}
3737

3838
$caches = $this->getCache()
39-
->call(
39+
->fetch(
4040
'caches.json',
4141
fn () => $this->scan()
4242
);

0 commit comments

Comments
 (0)