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
+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);
});