Skip to content

Commit

Permalink
Fixed caching to be provider-dependent.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Jun 21, 2020
1 parent 2cd8813 commit 3e95ab1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [4.3.4] - 2020-06-21
### Fixed
- non-caching declaration to only apply to current query.
- caching to take provider into account.

### Changed
- `getProvider()` method to no longer be deprecated, and instead return the
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderAndDumperAggregator.php
Expand Up @@ -197,7 +197,7 @@ protected function cacheRequest(string $cacheKey, array $queryElements, string $
return collect($this->aggregator->{$queryType}(...$queryElements));
}

$hashedCacheKey = sha1($cacheKey);
$hashedCacheKey = sha1($this->getProvider()->getName() . "-" . $cacheKey);
$duration = config("geocoder.cache.duration", 0);
$store = config('geocoder.cache.store');

Expand Down
9 changes: 7 additions & 2 deletions tests/Feature/Providers/GeocoderServiceTest.php
Expand Up @@ -160,7 +160,10 @@ public function testGeocoder()

public function testCacheIsUsed()
{
$cacheKey = sha1(Str::slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA'))));
$cacheKey = sha1(
app('geocoder')->getProvider()->getName()
. "-" . Str::slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')))
);

$result = app('geocoder')
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
Expand Down Expand Up @@ -271,7 +274,9 @@ public function testGetProvider()

public function testJapaneseCharacterGeocoding()
{
$cacheKey = sha1(Str::slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3'))));
$cacheKey = sha1(app('geocoder')->getProvider()->getName()
. "-" . Str::slug(strtolower(urlencode('108-0075 東京都港区港南2丁目16-3')))
);

app('geocoder')
->geocode('108-0075 東京都港区港南2丁目16-3')
Expand Down

0 comments on commit 3e95ab1

Please sign in to comment.