Skip to content

Commit

Permalink
Fixing caching of class loading in App class, this was broken after a…
Browse files Browse the repository at this point in the history
… 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++
  • Loading branch information
lorenzo committed Jul 16, 2011
1 parent ca0dccb commit c6c1bf1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
34 changes: 18 additions & 16 deletions lib/Cake/Core/App.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -501,15 +501,15 @@ public static function objects($type, $path = null, $cache = true) {
}
}

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];
Expand Down Expand Up @@ -776,8 +776,8 @@ private function _loadVendor($name, $plugin, $file, $ext) {
* @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');
}
Expand All @@ -797,7 +797,9 @@ private static function __map($file, $name, $plugin = null) {
} else {
self::$__map[$name] = $file;
}
self::$_cacheChange = true;
if (!self::$bootstrapping) {
self::$_cacheChange = true;
}
}

/**
Expand Down Expand Up @@ -830,10 +832,10 @@ private static function __mapped($name, $plugin = null) {
* @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_');
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Core/Configure.php
Expand Up @@ -74,7 +74,7 @@ public static function bootstrap($boot = true) {
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')) {
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/bootstrap.php
Expand Up @@ -131,6 +131,7 @@
App::uses('Configure', 'Core');
App::uses('Cache', 'Cache');
App::uses('Object', 'Core');
App::$bootstrapping = true;

Configure::bootstrap(isset($boot) ? $boot : true);

Expand Down

0 comments on commit c6c1bf1

Please sign in to comment.