Skip to content

Commit 9f9df7f

Browse files
committed
Update cache key to work with non-roman alphabets
1 parent 5081daa commit 9f9df7f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/ProviderAndDumperAggregator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public function dump($dumper)
7474
*/
7575
public function geocode($value)
7676
{
77-
$cacheId = str_slug($value);
77+
$cacheKey = str_slug(strtolower(urlencode($value)));
7878
$this->results = cache()->remember(
79-
"geocoder-{$cacheId}",
79+
"geocoder-{$cacheKey}",
8080
config('geocoder.cache-duraction', 0),
8181
function () use ($value) {
8282
return parent::geocode($value);
@@ -101,9 +101,9 @@ public function get()
101101
*/
102102
public function reverse($latitude, $longitude)
103103
{
104-
$cacheId = str_slug("{$latitude}-{$longitude}");
104+
$cacheKey = str_slug(strtolower(urlencode("{$latitude}-{$longitude}")));
105105
$this->results = cache()->remember(
106-
"geocoder-{$cacheId}",
106+
"geocoder-{$cacheKey}",
107107
config('geocoder.cache-duraction', 0),
108108
function () use ($latitude, $longitude) {
109109
return parent::reverse($latitude, $longitude);

tests/Laravel5_3/Providers/GeocoderServiceTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,20 @@ public function testCacheIsUsed()
178178
{
179179
$result = app('geocoder')->geocode('1600 Pennsylvania Ave., Washington, DC USA')
180180
->get();
181-
$cacheKey = 'geocoder-' . str_slug('1600 Pennsylvania Ave., Washington, DC USA');
181+
$cacheKey = str_slug(strtolower(urlencode('1600 Pennsylvania Ave., Washington, DC USA')));
182182

183-
$this->assertTrue(cache()->has($cacheKey));
184-
$this->assertEquals($result, cache($cacheKey));
183+
$this->assertEquals($result, cache("geocoder-{$cacheKey}"));
184+
$this->assertTrue(cache()->has("geocoder-{$cacheKey}"));
185+
}
186+
187+
public function testJapaneseCharacterGeocoding()
188+
{
189+
$cacheKey = str_slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')));
190+
191+
app('geocoder')->geocode('108-0075 東京都港区港南2丁目16-3')
192+
->get();
193+
194+
$this->assertEquals($cacheKey, '108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93');
195+
$this->assertTrue(cache()->has("geocoder-{$cacheKey}"));
185196
}
186197
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy