From: Evan Prodromou Date: Fri, 4 Dec 2009 21:25:05 +0000 (-0500) Subject: configurable expiry for cached Geonames data defaults to 90 days X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=098426cee901d264332c0ad0dd2155d30487d35f;p=quix0rs-gnu-social.git configurable expiry for cached Geonames data defaults to 90 days --- diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php index fdbf79e413..a750f12426 100644 --- a/plugins/GeonamesPlugin.php +++ b/plugins/GeonamesPlugin.php @@ -54,6 +54,7 @@ class GeonamesPlugin extends Plugin public $host = 'ws.geonames.org'; public $username = null; public $token = null; + public $expiry = 7776000; // 90-day expiry /** * convert a name into a Location object @@ -197,6 +198,9 @@ class GeonamesPlugin extends Plugin function onLocationFromLatLon($lat, $lon, $language, &$location) { + $lat = rtrim($lat, "0"); + $lon = rtrim($lon, "0"); + $loc = $this->getCache(array('lat' => $lat, 'lon' => $lon)); @@ -380,7 +384,11 @@ class GeonamesPlugin extends Plugin return null; } - return $c->get($this->cacheKey($attrs)); + $key = $this->cacheKey($attrs); + + $value = $c->get($key); + + return $value; } function setCache($attrs, $loc) @@ -391,18 +399,11 @@ class GeonamesPlugin extends Plugin return null; } - $c->set($this->cacheKey($attrs), $loc); - } - - function clearCache($attrs) - { - $c = common_memcache(); + $key = $this->cacheKey($attrs); - if (empty($c)) { - return null; - } + $result = $c->set($key, $loc, 0, time() + $this->expiry); - $c->delete($this->cacheKey($attrs)); + return $result; } function cacheKey($attrs)