]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'master' of gitorious.org:statusnet/mainline
authorBrion Vibber <brion@pobox.com>
Tue, 7 Dec 2010 20:13:50 +0000 (12:13 -0800)
committerBrion Vibber <brion@pobox.com>
Tue, 7 Dec 2010 20:13:50 +0000 (12:13 -0800)
README
lib/cache.php
lib/default.php
lib/router.php

diff --git a/README b/README
index b36d8b745402146c9c5d5c7627386fe22cd762de..5731ab3433283aa38ef49f375e3fde4fd712ab0c 100644 (file)
--- a/README
+++ b/README
@@ -1540,6 +1540,18 @@ external: external links in notices. One of three values: 'sometimes',
     nofollowed on profile, notice, and favorites page. Default is
     'sometimes'.
 
+router
+------
+
+We use a router class for mapping URLs to code. This section controls
+how that router works.
+
+cache: whether to cache the router in memcache (or another caching
+    mechanism). Defaults to true, but may be set to false for
+    developers (who might be actively adding pages, so won't want the
+    router cached) or others who see strange behavior. You're unlikely
+    to need this unless you're a developer.
+
 Plugins
 =======
 
index ea0ff769d1992c4b9e16690777bd104311d531ce..dc667654ab6ef327e8a022ae1b13d7612ecfa1b2 100644 (file)
@@ -86,6 +86,55 @@ class Cache
         return 'statusnet:' . $base_key . ':' . $extra;
     }
 
+    /**
+     * Create a cache key for data dependent on code
+     *
+     * For cache elements that are dependent on changes in code, this creates
+     * a more-or-less fingerprint of the current running code and adds it to
+     * the cache key. In the case of an upgrade of core, or addition or
+     * removal of plugins, a new unique fingerprint is generated and used.
+     * 
+     * There can still be problems with a) differences in versions of the 
+     * plugins and b) people running code between official versions. This is
+     * usually a problem only for experienced users like developers, who know
+     * how to clear their cache.
+     *
+     * For sites that run code between versions (like the status.net cloud),
+     * there's an additional build number configuration setting.
+     * 
+     * @param string $extra the real part of the key
+     *
+     * @return string full key
+     */
+    
+    static function codeKey($extra)
+    {
+        static $prefix = null;
+       
+        if (empty($prefix)) {
+           
+            $plugins     = StatusNet::getActivePlugins();
+            $names       = array();
+           
+            foreach ($plugins as $plugin) {
+                $names[] = $plugin[0];
+            }
+           
+            $names = array_unique($names);
+            asort($names);
+           
+            // Unique enough.
+       
+            $uniq = crc32(implode(',', $names));
+
+            $build = common_config('site', 'build');
+
+            $prefix = STATUSNET_VERSION.':'.$build.':'.$uniq;
+        }
+       
+        return Cache::key($prefix.':'.$extra);
+    }
+    
     /**
      * Make a string suitable for use as a key
      *
index a19453fce49ddb3ec2edcd61f78e42f9220b395f..85d27f5220b2c28722dcfcd7678fdd7041c214b4 100644 (file)
@@ -59,7 +59,8 @@ $default =
               'textlimit' => 140,
               'indent' => true,
               'use_x_sendfile' => false,
-              'notice' => null // site wide notice text
+              'notice' => null, // site wide notice text
+              'build' => 1, // build number, for code-dependent cache
               ),
         'db' =>
         array('database' => 'YOU HAVE TO SET THIS IN config.php',
@@ -323,4 +324,6 @@ $default =
         array('ssl_cafile' => false, // To enable SSL cert validation, point to a CA bundle (eg '/usr/lib/ssl/certs/ca-certificates.crt')
               'curl' => false, // Use CURL backend for HTTP fetches if available. (If not, PHP's socket streams will be used.)
               ),
+       'router' =>
+       array('cache' => true), // whether to cache the router object. Defaults to true, turn off for devel
         );
index 2a908c7e03ab76df630a8e1ebb36c3f4922a16b1..e4d5e5286a0658e7b04fc82f074c6dc9e2e40318 100644 (file)
@@ -127,15 +127,19 @@ class Router
     function __construct()
     {
         if (empty($this->m)) {
-            $k = self::cacheKey();
-            $c = Cache::instance();
-            $m = $c->get($k);
-            if (!empty($m)) {
-                $this->m = $m;
-            } else {
+           if (!common_config('router', 'cache')) {
                 $this->m = $this->initialize();
-                $c->set($k, $this->m);
-            }
+           } else {
+               $k = self::cacheKey();
+               $c = Cache::instance();
+               $m = $c->get($k);
+               if (!empty($m)) {
+                   $this->m = $m;
+               } else {
+                   $this->m = $this->initialize();
+                   $c->set($k, $this->m);
+               }
+           }
         }
     }
 
@@ -156,21 +160,7 @@ class Router
     
     static function cacheKey()
     {
-        $plugins     = StatusNet::getActivePlugins();
-        $names       = array();
-       
-        foreach ($plugins as $plugin) {
-            $names[] = $plugin[0];
-        }
-
-        $names = array_unique($names);
-        asort($names);
-
-        // Unique enough.
-       
-        $uniq = crc32(implode(',', $names));
-       
-        return Cache::key('router:'.STATUSNET_VERSION.':'.$uniq);
+        return Cache::codeKey('router');
     }
     
     function initialize()