diff options
author | Brion Vibber <brion@pobox.com> | 2010-12-07 12:13:50 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-12-07 12:13:50 -0800 |
commit | 001512df966c8c3b8f045f645e804b0a6fef8625 (patch) | |
tree | 3dc6f908daf11571f75bb222745c01313badeeb2 /lib | |
parent | db4d69f09953ddf89d6c970b40ca6a4094bf6e52 (diff) | |
parent | b35352790f17ddaca4debe767f22198cf0343cbc (diff) |
Merge branch 'master' of gitorious.org:statusnet/mainline
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cache.php | 49 | ||||
-rw-r--r-- | lib/default.php | 5 | ||||
-rw-r--r-- | lib/router.php | 36 |
3 files changed, 66 insertions, 24 deletions
diff --git a/lib/cache.php b/lib/cache.php index ea0ff769d..dc667654a 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -87,6 +87,55 @@ class Cache } /** + * 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 * * Useful for turning primary keys of tables into cache keys. diff --git a/lib/default.php b/lib/default.php index a19453fce..85d27f522 100644 --- a/lib/default.php +++ b/lib/default.php @@ -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 ); diff --git a/lib/router.php b/lib/router.php index 2a908c7e0..e4d5e5286 100644 --- a/lib/router.php +++ b/lib/router.php @@ -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() |