|
30 | 30 | use Illuminate\Support\Collection; |
31 | 31 | use Illuminate\Support\Facades\Log; |
32 | 32 | use Illuminate\Support\Facades\Notification; |
33 | | -use Illuminate\Support\Facades\Redis; |
34 | 33 |
|
35 | 34 | class ExpeditionService |
36 | 35 | { |
@@ -83,7 +82,7 @@ public function store(Project $project, array $request): mixed |
83 | 82 | }); |
84 | 83 |
|
85 | 84 | // Post-commit: Clear caches (outside tx to ensure commit first) |
86 | | - $this->clearExpeditionCache($project->id, $expedition->id ?? null); |
| 85 | + \Artisan::call('lada-cache:flush'); |
87 | 86 |
|
88 | 87 | return $expedition; |
89 | 88 |
|
@@ -370,8 +369,8 @@ public function update(Expedition $expedition, array $request): Expedition |
370 | 369 | return $expedition; |
371 | 370 | }); |
372 | 371 |
|
373 | | - // Clear only expedition-related cache |
374 | | - $this->clearExpeditionCache($expedition->project_id, $expedition->id); |
| 372 | + // Post-commit: Clear caches (outside tx to ensure commit first) |
| 373 | + \Artisan::call('lada-cache:flush'); |
375 | 374 |
|
376 | 375 | return $expedition; |
377 | 376 | } |
@@ -523,50 +522,4 @@ private function removeOldLogo(Expedition $expedition): void |
523 | 522 | \Log::error("Failed to remove old logo for expedition {$expedition->id}: ".$e->getMessage()); |
524 | 523 | } |
525 | 524 | } |
526 | | - |
527 | | - /** |
528 | | - * Clear targeted Lada-cache for expeditions (table/project/row level). |
529 | | - * Lada-cache was not clearing the project-level expeditions list. |
530 | | - */ |
531 | | - private function clearExpeditionCache(int $projectId, ?int $expeditionId = null): void |
532 | | - { |
533 | | - try { |
534 | | - $redisConnection = config('lada-cache.redis_connection', 'cache'); |
535 | | - $prefix = config('lada-cache.prefix', 'lada:'); |
536 | | - $redis = Redis::connection($redisConnection); |
537 | | - |
538 | | - // Patterns: Broaden for list queries (e.g., project expeditions collection) |
539 | | - $patterns = [ |
540 | | - $prefix.'*expeditions*', // Any expedition queries |
541 | | - $prefix.'*actor_expedition*', // Pivot relations |
542 | | - $prefix.'*expedition_stats*', // Stats |
543 | | - $prefix.'*projects*expeditions*', // Project->expeditions lists |
544 | | - $prefix.'*project_id:'.$projectId.'*', // Project-specific (e.g., lists) |
545 | | - ]; |
546 | | - |
547 | | - if ($expeditionId) { |
548 | | - $patterns[] = $prefix.'*expedition_id:'.$expeditionId.'*'; // Row-specific if hashed that way |
549 | | - } |
550 | | - |
551 | | - $totalCleared = 0; |
552 | | - foreach ($patterns as $pattern) { |
553 | | - $keys = $redis->keys($pattern); |
554 | | - if (! empty($keys)) { |
555 | | - $redis->del($keys); |
556 | | - $totalCleared += count($keys); |
557 | | - Log::info('Cleared Lada-cache keys', ['pattern' => $pattern, 'count' => count($keys)]); |
558 | | - } |
559 | | - } |
560 | | - |
561 | | - if ($totalCleared > 0) { |
562 | | - Log::info('Expedition cache cleared post-create', ['project_id' => $projectId, 'total_keys' => $totalCleared]); |
563 | | - } |
564 | | - |
565 | | - } catch (\Exception $e) { |
566 | | - Log::warning('Failed to clear expedition cache', [ |
567 | | - 'project_id' => $projectId, |
568 | | - 'error' => $e->getMessage(), |
569 | | - ]); |
570 | | - } |
571 | | - } |
572 | 525 | } |
0 commit comments