feat: forcibly invalidate availabilities cache on booking start

This commit is contained in:
Björn Fromme
2026-03-16 12:00:56 +01:00
parent 3c2ade9299
commit 79b7e2aaa5
3 changed files with 15 additions and 10 deletions
+2 -2
View File
@@ -75,8 +75,8 @@ class BookingEditDataLoaderService
} }
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId); $mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
// Using cached: true populates the cache for subsequent participant form loads // Force refresh ensures fresh data at edit start, then populates cache for subsequent loads
$availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId, cached: true); $availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId, cached: true, forceRefresh: true);
if (null === $mutableData || null === $availabilities) { if (null === $mutableData || null === $availabilities) {
return null; return null;
+2 -2
View File
@@ -236,8 +236,8 @@ class BookingService
} }
// Fetch and patch availability data (includes allowedBookingStatus from API) // Fetch and patch availability data (includes allowedBookingStatus from API)
// Using cached: true populates the cache for subsequent participant form loads // Force refresh ensures fresh data at booking start, then populates cache for subsequent loads
$availabilities = $this->travelDataService->getAvailabilityData($dateId, cached: true); $availabilities = $this->travelDataService->getAvailabilityData($dateId, cached: true, forceRefresh: true);
if (null !== $availabilities) { if (null !== $availabilities) {
$this->travelDataService->patchAvailabilities($travelData, $availabilities); $this->travelDataService->patchAvailabilities($travelData, $availabilities);
} }
+10 -5
View File
@@ -33,6 +33,7 @@ class TravelDataService
{ {
public const SOURCE_LOCAL = 'local'; public const SOURCE_LOCAL = 'local';
public const SOURCE_REMOTE = 'remote'; public const SOURCE_REMOTE = 'remote';
private const AVAILABILITY_CACHE_TTL = 600;
public function __construct( public function __construct(
private readonly TravelLoader $travelLoader, private readonly TravelLoader $travelLoader,
@@ -523,19 +524,23 @@ class TravelDataService
* Gets availability data for a travel date. * Gets availability data for a travel date.
* *
* @param int $dateId The travel date ID for API call * @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 bool $cached Whether to use cached data (default: false)
* @param int $ttl Cache TTL in seconds when $cached is true (default: 600 seconds) * @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 * @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) { if ($cached) {
$cacheKey = sprintf('availability_%d', $dateId); $cacheKey = sprintf('availability_%d', $dateId);
try { try {
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId, $ttl) { if ($forceRefresh) {
$item->expiresAfter($ttl); $this->cache->delete($cacheKey);
}
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId) {
$item->expiresAfter(self::AVAILABILITY_CACHE_TTL);
return $this->fetchAvailabilityData($dateId); return $this->fetchAvailabilityData($dateId);
}); });