]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Shared cache key option for Geonames plugin, lets multi-instance sites share their...
authorBrion Vibber <brion@pobox.com>
Tue, 30 Mar 2010 19:19:25 +0000 (12:19 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 30 Mar 2010 19:20:46 +0000 (12:20 -0700)
Example:
  unset($config['plugins']['default']['Geonames']);
  addPlugin('Geonames', array('cachePrefix' => 'statusnet:shared'));

plugins/GeonamesPlugin.php

index 589462ed9936399492436536a8c5ca248e96ca4b..f018e269439f5d6bf3e0e5e2efd5c2f4db5ef7ad 100644 (file)
@@ -55,6 +55,8 @@ class GeonamesPlugin extends Plugin
     public $username = null;
     public $token    = null;
     public $expiry   = 7776000; // 90-day expiry
+    public $cachePrefix = null; // Optional shared memcache prefix override
+                                // to share lookups between local instances.
 
     /**
      * convert a name into a Location object
@@ -408,9 +410,14 @@ class GeonamesPlugin extends Plugin
 
     function cacheKey($attrs)
     {
-        return common_cache_key('geonames:'.
-                                implode(',', array_keys($attrs)) . ':'.
-                                common_keyize(implode(',', array_values($attrs))));
+        $key = 'geonames:' .
+               implode(',', array_keys($attrs)) . ':'.
+               common_keyize(implode(',', array_values($attrs)));
+        if ($this->cachePrefix) {
+            return $this->cachePrefix . ':' . $key;
+        } else {
+            return common_cache_key($key);
+        }
     }
 
     function wsUrl($method, $params)