Skip to content

Commit e9eb75e

Browse files
samybassetNyholm
authored andcommitted
Add optional precision argument (#204)
* Add cache_precision to BazingaGeoCoderExtension * Update docs
1 parent f7755fc commit e9eb75e

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

DependencyInjection/BazingaGeocoderExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con
111111
}
112112
}
113113

114-
if (isset($config['cache']) || isset($config['cache_lifetime'])) {
114+
if (isset($config['cache']) || isset($config['cache_lifetime']) || isset($config['cache_precision'])) {
115115
if (null === $cacheServiceId = $config['cache']) {
116116
if (!$container->has('app.cache')) {
117117
throw new \LogicException('You need to specify a service for cache.');
@@ -121,7 +121,7 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con
121121
$plugins[] = $providerServiceId.'.cache';
122122
$container->register($providerServiceId.'.cache', CachePlugin::class)
123123
->setPublic(false)
124-
->setArguments([new Reference($cacheServiceId), (int) $config['cache_lifetime']]);
124+
->setArguments([new Reference($cacheServiceId), (int) $config['cache_lifetime'], $config['cache_precision']]);
125125
}
126126

127127
if (isset($config['limit'])) {

DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ private function getProvidersNode()
9898
->variableNode('options')->defaultValue([])->end()
9999
->scalarNode('cache')->defaultNull()->end()
100100
->scalarNode('cache_lifetime')->defaultNull()->end()
101+
->scalarNode('cache_precision')
102+
->defaultNull()
103+
->info('Precision of the coordinates to cache.')
104+
->end()
101105
->scalarNode('limit')->defaultNull()->end()
102106
->scalarNode('locale')->defaultNull()->end()
103107
->scalarNode('logger')->defaultNull()->end()

Resources/doc/cache.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ bazinga_geocoder:
1414
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
1515
cache: 'any.psr16.service'
1616
cache_lifetime: 3600
17+
cache_precision: ~
1718
```
1819
20+
If you do a lot of reverse queries it can be useful to cache them with less precision. So if you are interested in only the city,
21+
you don't want to query for every exact coordinate. Instead, you want to remove some precision of the coordinates. For example:
22+
reversing `52.3705273, 4.891031` will be cached as `52.3705, 4.8910`.
23+
1924
You may use any [PSR16](http://www.php-fig.org/psr/psr-16/) cache [implementation](https://packagist.org/providers/psr/simple-cache-implementation).
2025
The `CachePlugin` helps you to cache all responses.
2126

@@ -79,6 +84,7 @@ bazinga_geocoder:
7984
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
8085
cache: 'app.simple_cache'
8186
cache_lifetime: 3600
87+
cache_precision: 4
8288
```
8389

8490
For older Symfony version, you can use a bridge between PSR-6 and PSR-16. Install the

Resources/doc/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ bazinga_geocoder:
265265
factory: ~ # Required
266266
cache: 'app.cache'
267267
cache_lifetime: 3600
268+
cache_precision: 4 # Precision of the coordinates to cache.
268269
limit: 5
269270
locale: 'sv'
270271
logger: 'logger'

Tests/Functional/config/cache.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ bazinga_geocoder:
66
acme:
77
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
88
cache_lifetime: 10
9+
cache_precision: 4
910
cache: acme.cache
1011

1112
services:

0 commit comments

Comments
 (0)