| @@ -371,9 +371,9 @@ | ||
| 371 | 371 | if (method_exists($repository, 'paginate')) { |
| 372 | 372 | // Try the new signature first: paginate(int $page, int $perPage, array $filters) |
| 373 | 373 | try { |
| 374 | 374 | return $repository->paginate($page, $perPage, $filters); |
| 375 | - } catch (ArgumentCountError $e) { | |
| 375 | + } catch (\ArgumentCountError $e) { | |
| 376 | 376 | // Fall back to old signature: paginate(array $filters) |
| 377 | 377 | $filters['page'] = $page; |
| 378 | 378 | $filters['per_page'] = $perPage; |
| 379 | 379 | return $repository->paginate($filters); |
| @@ -445,18 +445,19 @@ | ||
| 445 | 445 | return; // No cache to clear |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | $entityType = strtolower(str_replace(['\\', 'Service'], ['_', ''], static::class)); |
| 449 | + | |
| 450 | + // The cache keys generated by getCacheKey() are prefixed with "service_{$entityType}_..." | |
| 451 | + // and use a params hash, so prefix deletion by "{$entityType}_..." would miss them. | |
| 452 | + // To avoid stale admin reads, clear the whole service keyspace and also delete the most | |
| 453 | + // common single-entity keys directly. | |
| 454 | + Cache::delete($this->getCacheKey('entity', ['id' => $id])); | |
| 455 | + Cache::delete($this->getCacheKey('exists', ['id' => $id])); | |
| 456 | + | |
| 457 | + // Clear all caches for this service (covers all/all/count/paginate variants). | |
| 458 | + $this->clearCacheByPattern("service_{$entityType}_"); | |
| 449 | 459 | |
| 450 | - // Clear specific entity cache | |
| 451 | - $this->clearCacheByPattern("{$entityType}_entity_{$id}"); | |
| 452 | - | |
| 453 | - // Clear related list caches | |
| 454 | - $this->clearCacheByPattern("{$entityType}_all"); | |
| 455 | - $this->clearCacheByPattern("{$entityType}_count"); | |
| 456 | - $this->clearCacheByPattern("{$entityType}_exists_{$id}"); | |
| 457 | - $this->clearCacheByPattern("{$entityType}_paginate"); | |
| 458 | - | |
| 459 | 460 | // Clear query result caches |
| 460 | 461 | $this->clearCacheByPattern(Cache::PREFIX_QUERY_RESULT); |
| 461 | 462 | |
| 462 | 463 | Logger::info("Entity cache cleared", [ |
| @@ -476,10 +477,10 @@ | ||
| 476 | 477 | } |
| 477 | 478 | |
| 478 | 479 | $entityType = strtolower(str_replace(['\\', 'Service'], ['_', ''], static::class)); |
| 479 | 480 | |
| 480 | - // Clear all caches related to this service | |
| 481 | - $this->clearCacheByPattern($entityType); | |
| 481 | + // Clear all caches related to this service (see getCacheKey()). | |
| 482 | + $this->clearCacheByPattern("service_{$entityType}_"); | |
| 482 | 483 | |
| 483 | 484 | Logger::info("All service cache cleared", [ |
| 484 | 485 | 'service' => static::class, |
| 485 | 486 | 'entity_type' => $entityType |
| @@ -582,9 +583,9 @@ | ||
| 582 | 583 | if (count($existingMetrics) > 1000) { |
| 583 | 584 | $existingMetrics = array_slice($existingMetrics, -1000); |
| 584 | 585 | } |
| 585 | 586 | |
| 586 | - update_option('yatra_cache_metrics', $existingMetrics); | |
| 587 | + update_option('yatra_cache_metrics', $existingMetrics, false); // autoload=false: metrics, read on demand | |
| 587 | 588 | |
| 588 | 589 | } catch (\Exception $e) { |
| 589 | 590 | // Don't let metrics storage failures break the main functionality |
| 590 | 591 | Logger::debug("Failed to store cache metrics", [ |