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);
// 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;
+2 -2
View File
@@ -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);
}
+11 -6
View File
@@ -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);
});