diff --git a/src/Service/BookingEditDataLoaderService.php b/src/Service/BookingEditDataLoaderService.php index c231d21..0831c3c 100644 --- a/src/Service/BookingEditDataLoaderService.php +++ b/src/Service/BookingEditDataLoaderService.php @@ -75,8 +75,8 @@ class BookingEditDataLoaderService } $mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId); - // Using cached: true populates the cache for subsequent participant form loads - $availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId, cached: true); + // Force refresh ensures fresh data at edit start, then populates cache for subsequent loads + $availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId, cached: true, forceRefresh: true); if (null === $mutableData || null === $availabilities) { return null; diff --git a/src/Service/BookingService.php b/src/Service/BookingService.php index dbb83d7..ac0b406 100644 --- a/src/Service/BookingService.php +++ b/src/Service/BookingService.php @@ -236,8 +236,8 @@ class BookingService } // Fetch and patch availability data (includes allowedBookingStatus from API) - // Using cached: true populates the cache for subsequent participant form loads - $availabilities = $this->travelDataService->getAvailabilityData($dateId, cached: true); + // Force refresh ensures fresh data at booking start, then populates cache for subsequent loads + $availabilities = $this->travelDataService->getAvailabilityData($dateId, cached: true, forceRefresh: true); if (null !== $availabilities) { $this->travelDataService->patchAvailabilities($travelData, $availabilities); } diff --git a/src/Service/TravelDataService.php b/src/Service/TravelDataService.php index 03ea4b0..2edf2df 100644 --- a/src/Service/TravelDataService.php +++ b/src/Service/TravelDataService.php @@ -33,6 +33,7 @@ class TravelDataService { public const SOURCE_LOCAL = 'local'; public const SOURCE_REMOTE = 'remote'; + private const AVAILABILITY_CACHE_TTL = 600; public function __construct( private readonly TravelLoader $travelLoader, @@ -522,20 +523,24 @@ class TravelDataService /** * Gets availability data for a travel date. * - * @param int $dateId The travel date ID for API call - * @param bool $cached Whether to use cached data (default: false, TTL when cached: 600 seconds) - * @param int $ttl Cache TTL in seconds when $cached is true (default: 600 seconds) + * @param int $dateId The travel date ID for API call + * @param bool $cached Whether to use cached data (default: false) + * @param bool $forceRefresh Whether to invalidate cache before fetching (requires cached: true) * * @return ServiceAvailabilityResponse|null The availability data or null if not available or error occurred */ - public function getAvailabilityData(int $dateId, bool $cached = false, int $ttl = 600): ?ServiceAvailabilityResponse + public function getAvailabilityData(int $dateId, bool $cached = false, bool $forceRefresh = false): ?ServiceAvailabilityResponse { if ($cached) { $cacheKey = sprintf('availability_%d', $dateId); try { - return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId, $ttl) { - $item->expiresAfter($ttl); + if ($forceRefresh) { + $this->cache->delete($cacheKey); + } + + return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId) { + $item->expiresAfter(self::AVAILABILITY_CACHE_TTL); return $this->fetchAvailabilityData($dateId); });