From 098426cee901d264332c0ad0dd2155d30487d35f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 4 Dec 2009 16:25:05 -0500 Subject: [PATCH] configurable expiry for cached Geonames data defaults to 90 days --- plugins/GeonamesPlugin.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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); - } + $key = $this->cacheKey($attrs); - function clearCache($attrs) - { - $c = common_memcache(); + $result = $c->set($key, $loc, 0, time() + $this->expiry); - if (empty($c)) { - return null; - } - - $c->delete($this->cacheKey($attrs)); + return $result; } function cacheKey($attrs)