From c6c1bf110dd9df6ce01e6a220e3f77262a73818f Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 15 Jul 2011 20:44:39 -0430 Subject: [PATCH] Fixing caching of class loading in App class, this was broken after a recent refactoring Additionally a new property $bootstrapping is added to App, this is set during the bootstrap process to indicate that classes loaded before the caching is initialized should not trigger the cache write routine. Performance++ --- lib/Cake/Core/App.php | 34 ++++++++++++++++++---------------- lib/Cake/Core/Configure.php | 2 +- lib/Cake/bootstrap.php | 1 + 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 0e664549e..34085d666 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -117,13 +117,6 @@ class App { */ public static $return = false; -/** - * Determines if $__maps and $__paths cache should be written. - * - * @var boolean - */ - private static $__cache = false; - /** * Holds key/value pairs of $type => file path. * @@ -198,6 +191,13 @@ class App { */ private static $_objectCacheChange = false; +/** + * Indicates the the Application is in the bootstrapping process. Used to better cache + * loaded classes while the cache libraries have not been yet initialized + * + */ + public static $bootstrapping = false; + /** * Used to read information stored path * @@ -501,15 +501,15 @@ class App { } } - if ($cache === true) { - self::$__cache = true; - } sort($objects); if ($plugin) { return $objects; } + self::$__objects[$cacheLocation][$name] = $objects; - self::$_objectCacheChange = true; + if ($cache) { + self::$_objectCacheChange = true; + } } return self::$__objects[$cacheLocation][$name]; @@ -776,8 +776,8 @@ class App { * @return void */ public static function init() { - self::$__map = (array)Cache::read('file_map', '_cake_core_'); - self::$__objects = (array)Cache::read('object_map', '_cake_core_'); + self::$__map += (array)Cache::read('file_map', '_cake_core_'); + self::$__objects += (array)Cache::read('object_map', '_cake_core_'); register_shutdown_function(array('App', 'shutdown')); self::uses('CakePlugin', 'Core'); } @@ -797,7 +797,9 @@ class App { } else { self::$__map[$name] = $file; } - self::$_cacheChange = true; + if (!self::$bootstrapping) { + self::$_cacheChange = true; + } } /** @@ -830,10 +832,10 @@ class App { * @return void */ public static function shutdown() { - if (self::$__cache && self::$_cacheChange) { + if (self::$_cacheChange) { Cache::write('file_map', array_filter(self::$__map), '_cake_core_'); } - if (self::$__cache && self::$_objectCacheChange) { + if (self::$_objectCacheChange) { Cache::write('object_map', self::$__objects, '_cake_core_'); } } diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index 91160ca9e..b8421c66d 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -74,7 +74,7 @@ class Configure { if (!include(APP . 'Config' . DS . 'core.php')) { trigger_error(__d('cake_dev', "Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR); } - + App::$bootstrapping = false; App::init(); App::build(); if (!include(APP . 'Config' . DS . 'bootstrap.php')) { diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index bcef50863..52bbf9dbc 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -131,6 +131,7 @@ App::uses('ErrorHandler', 'Error'); App::uses('Configure', 'Core'); App::uses('Cache', 'Cache'); App::uses('Object', 'Core'); +App::$bootstrapping = true; Configure::bootstrap(isset($boot) ? $boot : true);