From 266c7eaeae49f0cfe4ee8f0a0dd3037085e61aa8 Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Fri, 6 Feb 2026 09:29:04 +0800 Subject: [PATCH] add app cache clear --- backend/app/Command/AppCacheClear.php | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 backend/app/Command/AppCacheClear.php diff --git a/backend/app/Command/AppCacheClear.php b/backend/app/Command/AppCacheClear.php new file mode 100644 index 0000000..1428373 --- /dev/null +++ b/backend/app/Command/AppCacheClear.php @@ -0,0 +1,71 @@ +setDescription('Clear application caches (proxy, runtime)'); + } + + public function handle(): void + { + $basePath = BASE_PATH . '/runtime'; + + $directories = [ + $basePath . '/container/proxy', + $basePath . '/container/aspects', + $basePath . '/cache', + ]; + + $clearedCount = 0; + + foreach ($directories as $dir) { + if (is_dir($dir)) { + $files = glob($dir . '/*'); + foreach ($files as $file) { + if (is_file($file)) { + unlink($file); + $clearedCount++; + } elseif (is_dir($file)) { + $this->removeDirectory($file); + $clearedCount++; + } + } + $this->info("Cleared: {$dir}"); + } else { + $this->line("Skipped (not exists): {$dir}"); + } + } + + $this->info("Cache cleared. Removed {$clearedCount} items."); + } + + private function removeDirectory(string $dir): void + { + if (!is_dir($dir)) { + return; + } + + $files = array_diff(scandir($dir), ['.', '..']); + foreach ($files as $file) { + $path = $dir . '/' . $file; + is_dir($path) ? $this->removeDirectory($path) : unlink($path); + } + rmdir($dir); + } +}