feat: forcibly invalidate availabilities cache on booking start
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -522,20 +523,24 @@ 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);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user