refactor: scope postcode cache to place names, DB is authoritative for postcodes
This commit is contained in:
@@ -26,7 +26,16 @@ class PostcodeService
|
||||
public function resolve(string $query): ?LocationResult
|
||||
{
|
||||
$query = trim($query);
|
||||
$cacheKey = 'postcode:'.strtolower(preg_replace('/\s+/', '', $query));
|
||||
|
||||
if ($this->isFullPostcode($query)) {
|
||||
return $this->lookupLocalPostcode($query) ?? $this->lookupPostcode($query);
|
||||
}
|
||||
|
||||
if ($this->isOutcode($query)) {
|
||||
return $this->lookupLocalOutcode($query) ?? $this->lookupOutcode($query);
|
||||
}
|
||||
|
||||
$cacheKey = 'place:'.strtolower(preg_replace('/\s+/', '', $query));
|
||||
|
||||
$cached = Cache::get($cacheKey);
|
||||
|
||||
@@ -34,11 +43,7 @@ class PostcodeService
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$result = match (true) {
|
||||
$this->isFullPostcode($query) => $this->lookupLocalPostcode($query) ?? $this->lookupPostcode($query),
|
||||
$this->isOutcode($query) => $this->lookupLocalOutcode($query) ?? $this->lookupOutcode($query),
|
||||
default => $this->lookupPlace($query),
|
||||
};
|
||||
$result = $this->lookupPlace($query);
|
||||
|
||||
if ($result !== null) {
|
||||
Cache::put($cacheKey, $result, self::CACHE_TTL);
|
||||
|
||||
Reference in New Issue
Block a user