configurable expiry for cached Geonames data defaults to 90 days
This commit is contained in:
		@@ -54,6 +54,7 @@ class GeonamesPlugin extends Plugin
 | 
				
			|||||||
    public $host     = 'ws.geonames.org';
 | 
					    public $host     = 'ws.geonames.org';
 | 
				
			||||||
    public $username = null;
 | 
					    public $username = null;
 | 
				
			||||||
    public $token    = null;
 | 
					    public $token    = null;
 | 
				
			||||||
 | 
					    public $expiry   = 7776000; // 90-day expiry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * convert a name into a Location object
 | 
					     * convert a name into a Location object
 | 
				
			||||||
@@ -197,6 +198,9 @@ class GeonamesPlugin extends Plugin
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    function onLocationFromLatLon($lat, $lon, $language, &$location)
 | 
					    function onLocationFromLatLon($lat, $lon, $language, &$location)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        $lat = rtrim($lat, "0");
 | 
				
			||||||
 | 
					        $lon = rtrim($lon, "0");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $loc = $this->getCache(array('lat' => $lat,
 | 
					        $loc = $this->getCache(array('lat' => $lat,
 | 
				
			||||||
                                     'lon' => $lon));
 | 
					                                     'lon' => $lon));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -380,7 +384,11 @@ class GeonamesPlugin extends Plugin
 | 
				
			|||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $c->get($this->cacheKey($attrs));
 | 
					        $key = $this->cacheKey($attrs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $value = $c->get($key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $value;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function setCache($attrs, $loc)
 | 
					    function setCache($attrs, $loc)
 | 
				
			||||||
@@ -391,18 +399,11 @@ class GeonamesPlugin extends Plugin
 | 
				
			|||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $c->set($this->cacheKey($attrs), $loc);
 | 
					        $key = $this->cacheKey($attrs);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function clearCache($attrs)
 | 
					        $result = $c->set($key, $loc, 0, time() + $this->expiry);
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $c = common_memcache();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (empty($c)) {
 | 
					        return $result;
 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $c->delete($this->cacheKey($attrs));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function cacheKey($attrs)
 | 
					    function cacheKey($attrs)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user