Implemented Registry caching.
By changing the config.core.php file you can select how registries should be cached. Remember that this is not recommended during development. The available options are file, apc, redis, memcached, wincache and dummy. Cache TTL can also be set. Some caching drivers require you to change the config.cache.php file.
This commit is contained in:
parent
ae861b8b6e
commit
7e3e707d9f
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
return array(
|
||||
'enable_composer' => true,
|
||||
'composer_autoloader' => '',
|
||||
'enable_composer' => true,
|
||||
'composer_autoloader' => '',
|
||||
'registry_caching' => false,
|
||||
'registry_caching_method' => 'file',
|
||||
'registry_caching_time' => 300,
|
||||
);
|
||||
|
|
|
@ -93,7 +93,10 @@ class Core
|
|||
Router::init();
|
||||
|
||||
// Build all the registers for correct operation
|
||||
Modules::buildRegister();
|
||||
Modules::buildRegister($config->registry_caching,
|
||||
$config->registry_caching_method,
|
||||
$config->registry_caching_time
|
||||
);
|
||||
|
||||
// Load Composer
|
||||
if ($config->enable_composer) {
|
||||
|
|
|
@ -375,9 +375,29 @@ class Modules
|
|||
* Create a register with all the module headers from all the existing modules.
|
||||
*
|
||||
* Used to correctly load all modules
|
||||
* @param bool $cache true if loading from cache
|
||||
* @param string $cachingMethod the driver used in the caching library
|
||||
* @param int $cachingTime The time the registers are cached
|
||||
*/
|
||||
public static function buildRegister()
|
||||
public static function buildRegister($cache = false, $cachingMethod = 'file', $cachingTime = 300)
|
||||
{
|
||||
// First check if the caching engine can be used
|
||||
if ($cache)
|
||||
{
|
||||
$cache = Libraries::getDriver('cache');
|
||||
$moduleRegister = $cache->$cachingMethod->get('moduleRegister');
|
||||
$eventRegister = $cache->$cachingMethod->get('eventRegister');
|
||||
|
||||
if ( ! is_bool($moduleRegister) && ! is_bool($eventRegister) )
|
||||
{
|
||||
Logger::newLevel("Loadig Module Headers from Cache");
|
||||
self::$register = $moduleRegister;
|
||||
Events::$register = $eventRegister;
|
||||
Logger::stopLevel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Logger::newLevel('Loading Module Headers', 'Core');
|
||||
|
||||
// Get all the module directories
|
||||
|
@ -511,6 +531,13 @@ class Modules
|
|||
}
|
||||
}
|
||||
|
||||
if ($cache)
|
||||
{
|
||||
Logger::log("Saving registry to cache");
|
||||
$cache->$cachingMethod->save('moduleRegister', $register, $cachingTime);
|
||||
$cache->$cachingMethod->save('eventRegister', $event_register, $cachingTime);
|
||||
}
|
||||
|
||||
// And apply the registers to their dedicate location
|
||||
self::$register = $register;
|
||||
Events::$register = $event_register;
|
||||
|
|
Loading…
Reference in New Issue