1212use Windwalker \Console \CommandWrapper ;
1313use Windwalker \Console \CompletionContext ;
1414use Windwalker \Console \CompletionHandlerInterface ;
15+ use Windwalker \Console \Input \InputOption ;
1516use Windwalker \Console \IOInterface ;
1617use Windwalker \Core \Application \ApplicationInterface ;
1718use 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 /**
0 commit comments