Parse and validate AT Protocol Lexicons with DTO generation for Laravel
at dev 2.1 kB view raw
1<?php 2 3namespace SocialDept\AtpSchema\Console; 4 5use Illuminate\Console\Command; 6use Illuminate\Support\Facades\Cache; 7 8class ClearCacheCommand extends Command 9{ 10 /** 11 * The name and signature of the console command. 12 */ 13 protected $signature = 'schema:clear-cache 14 {--nsid= : Clear cache for a specific NSID} 15 {--all : Clear all schema caches}'; 16 17 /** 18 * The console command description. 19 */ 20 protected $description = 'Clear ATProto Lexicon schema caches'; 21 22 /** 23 * Execute the console command. 24 */ 25 public function handle(): int 26 { 27 $nsid = $this->option('nsid'); 28 $all = $this->option('all'); 29 30 if (! $nsid && ! $all) { 31 $this->error('Either --nsid or --all option must be provided'); 32 33 return self::FAILURE; 34 } 35 36 try { 37 $cachePrefix = config('schema.cache.prefix', 'schema'); 38 39 if ($all) { 40 $this->info('Clearing all schema caches...'); 41 42 // Clear all cache keys with the schema prefix 43 if (Cache::getStore() instanceof \Illuminate\Cache\TaggableStore) { 44 Cache::tags([$cachePrefix])->flush(); 45 } else { 46 // For non-taggable stores, we need to clear by pattern 47 $this->warn('Cache store does not support tags. Using Cache::flush() to clear all caches.'); 48 Cache::flush(); 49 } 50 51 $this->info('✓ All schema caches cleared'); 52 53 return self::SUCCESS; 54 } 55 56 $this->info("Clearing cache for schema: {$nsid}"); 57 58 $cacheKey = "{$cachePrefix}:parsed:{$nsid}"; 59 Cache::forget($cacheKey); 60 61 $this->info('✓ Cache cleared'); 62 63 return self::SUCCESS; 64 } catch (\Exception $e) { 65 $this->error('Failed to clear cache: '.$e->getMessage()); 66 67 if ($this->output->isVerbose()) { 68 $this->error($e->getTraceAsString()); 69 } 70 71 return self::FAILURE; 72 } 73 } 74}