Browse Source

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++

Jose Lorenzo Rodriguez 14 years ago
parent
commit
c6c1bf110d
3 changed files with 20 additions and 17 deletions
  1. 18 16
      lib/Cake/Core/App.php
  2. 1 1
      lib/Cake/Core/Configure.php
  3. 1 0
      lib/Cake/bootstrap.php

+ 18 - 16
lib/Cake/Core/App.php

@@ -118,13 +118,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.
  *
  * @var array
@@ -199,6 +192,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
  *
  * Usage:
@@ -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_');
 		}
 	}

+ 1 - 1
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')) {

+ 1 - 0
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);