geocoder-php/BazingaGeocoderBundle — pull request #79 by giosh94mhz (2014-07-03 10:09:47+00:00)
Title: CacheProvider: better hashing function and namespace

Hi William,
I've improved the cache key generation for the `CacheProvider`, to reduce cache pollution and reduce collision probability.

The main problem with the current implementation is that cache key are stored without any sort of namespaces. This is a problem, since a simple `crc32($ip)` for example has high probability of collision especially with old codebase. Also this may introduce security issue (just speculating, didn't tested actually): what if a malicious user types `"anotherpkg_hashkey"` as a string in a geocoding field? A simple namespace solves this issue. Note that this isn't a BC, since Cache interface documentation explicitly say that keys are strings (even if in the current implementation are numeric strings).

I've changed CRC32 to SHA1, which are comparable in terms of performance, but SHA1 is better suited for hashing (some source: https://web.archive.org/web/20120722074858/http://bretm.home.comcast.net/~bretm/hash/8.html ).

To further improve the cache hit ratio when reverse geocoding, the key can be generated with:
```php
$key = 'geocoder_' . sha1(sprintf("%s%.6F%.6F", $this->locale, $coordinates[0], $coordinates[1]);
```
but this may require some sanity check for the $coordinates array. What do you think?