Skip to content

Commit

Permalink
Add travel type filter to caching
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin committed Dec 13, 2024
1 parent 5c00732 commit 3c6aa95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/DataProviders/CachedHafas.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getDepartures(Station $station, Carbon $when, int $duration = 15
// set duration longer than 15 minutes
$duration = $duration < 15 ? 30 : $duration;

$key = CacheKey::getHafasDeparturesKey($station->id, $when, $localtime);
$key = CacheKey::getHafasDeparturesKey($station->id, $when, $localtime, $type);

$departures = $this->remember(
$key,
Expand Down
13 changes: 10 additions & 3 deletions app/Helpers/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace App\Helpers;

use App\Enum\TravelType;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
Expand All @@ -24,7 +25,7 @@ class CacheKey
private const string STATISTICS_GLOBAL = 'StatisticsGlobal';
private const string HAFAS_TRIP = '_HafasTrip_%s_%s';
private const string HAFAS_STATIONS = '_HafasStations';
private const string HAFAS_DEPARTURES = '_HafasDepartures_%d_%s_%s';
private const string HAFAS_DEPARTURES = '_HafasDepartures_%d_%s_%s_%s';
private const string HAFAFS_STATION_RIL = '_HafasStationRil';
private const string HAFAS_STATIONS_FUZZY = '_HafasStationsFuzzy';
private const string HAFAS_CACHE_HIT = '_HafasCacheHit_%s';
Expand Down Expand Up @@ -53,8 +54,14 @@ public static function getHafasStationsKey(string $query): string {
return sprintf(self::FOR, self::HAFAS_STATIONS, $query);
}

public static function getHafasDeparturesKey(string $stationId, Carbon $when, bool $localtime): string {
return sprintf(self::HAFAS_DEPARTURES, $stationId, $when->toTimeString(), $localtime ? 'local' : 'utc');
public static function getHafasDeparturesKey(string $stationId, Carbon $when, bool $localtime, ?TravelType $type): string {
return sprintf(
self::HAFAS_DEPARTURES,
$stationId,
$when->toTimeString(),
$localtime ? 'local' : 'utc',
$type ? $type->value : 'all'
);
}

public static function getHafasByRilIdentifierKey(string $rilIdentifier): string {
Expand Down

0 comments on commit 3c6aa95

Please sign in to comment.