Source of file CachedGeocodingService.php
Size: 1,162 Bytes - Last Modified: 2021-12-23T10:53:37+00:00
/var/www/docs.ssmods.com/process/src/code/CachedGeocodingService.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | <?php /** * @package geocoding */ class CachedGeocodingService implements IGeocodingService { /** * @var IGeocodingService */ protected $backend = null; function __construct(IGeocodingService $backend) { $this->backend = $backend; } /** * Gets the cache object * * @return Zend_Cache_Frontend */ protected function getCache() { return SS_Cache::factory('GeocodingService'); } public function geocode($address) { // Generate unique key for address $address = $this->normaliseAddress($address); $addressKey = md5('CachedGeocodingService_' . $address); // Check if cached $result = unserialize($this->getCache()->load($addressKey)); if($result) return $result; // generate result, and check if it's a cachable result $result = $this->backend->geocode($address); if($result['Cache']) { $oneWeek = 3600 * 24 * 7; $this->getCache()->save(serialize($result), $addressKey, array(), $oneWeek); } return $result; } public function isOverLimit() { return $this->backend->isOverLimit(); } public function normaliseAddress($address) { return $this->backend->normaliseAddress($address); } } |