| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Repositories; |
| 6 |
|
| 7 |
use Yatra\Utils\Cache; |
| 8 |
|
| 9 |
/** |
| 10 |
* Geocoding response cache (Nominatim). Not DB-backed; centralizes cache keys for external lookups. |
| 11 |
* Does not wrap {@see get_option()}. |
| 12 |
*/ |
| 13 |
final class GeocodingRepository |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @param string $schema Bump when search API parameters change (busts stale cache). |
| 17 |
*/ |
| 18 |
public function cacheKeySearch(string $query, int $limit, string $schema = 'v4'): string |
| 19 |
{ |
| 20 |
return 'yatra_geo_search_' . md5($query . '|' . $limit . '|' . $schema); |
| 21 |
} |
| 22 |
|
| 23 |
public function cacheKeyReverse(float $lat, float $lng): string |
| 24 |
{ |
| 25 |
return 'yatra_geo_reverse_' . md5((string) $lat . '_' . (string) $lng); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* @return mixed |
| 30 |
*/ |
| 31 |
public function getPayload(string $key) |
| 32 |
{ |
| 33 |
return Cache::get($key); |
| 34 |
} |
| 35 |
|
| 36 |
public function setPayload(string $key, $value, int $ttlSeconds): bool |
| 37 |
{ |
| 38 |
return Cache::set($key, $value, $ttlSeconds); |
| 39 |
} |
| 40 |
} |
| 41 |
|