summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-12-04 16:25:05 -0500
committerEvan Prodromou <evan@status.net>2009-12-04 16:25:05 -0500
commit098426cee901d264332c0ad0dd2155d30487d35f (patch)
tree41bb1eac82f074143249b5a98cfc306175788fc1
parent41f10b742c4c3c21a8783050c6bb55dad17f050d (diff)
configurable expiry for cached Geonames data defaults to 90 days
-rw-r--r--plugins/GeonamesPlugin.php23
1 files changed, 12 insertions, 11 deletions
diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php
index fdbf79e41..a750f1242 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)