Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Move cache initialization to bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Dec 8, 2015
1 parent 1281ee1 commit 198a048
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
45 changes: 42 additions & 3 deletions core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function _initDoctype()
$this->bootstrap('view');

/** @var Zend_View $view */
$view = $this->getResource('view');
$view = $this->getResource('View');
$view->doctype('XHTML1_STRICT');
}

Expand Down Expand Up @@ -109,6 +109,45 @@ protected function _initDatabase()
return false;
}

/**
* Initialize the cache.
*
* @return false|Zend_Cache_Core
*/
protected function _initCache()
{
$this->bootstrap('Config', 'Database');

if (Zend_Registry::get('configGlobal')->get('environment', 'production') === 'production') {
$frontendOptions = array(
'automatic_serialization' => true,
'lifetime' => 86400,
'cache_id_prefix' => 'midas_',
);

if (extension_loaded('memcached') || session_save_path() === 'Memcache') {
$cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array());
} elseif (extension_loaded('memcache')) {
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array());
} else {
$cacheDir = UtilityComponent::getCacheDirectory().'/db';

if (is_dir($cacheDir) && is_writable($cacheDir)) {
$backendOptions = array('cache_dir' => $cacheDir);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
}
}

if ($cache !== false) {
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
}
}

Zend_Registry::set('cache', $cache);

return $cache;
}

/** Initialize the error handler. */
protected function _initErrorHandle()
{
Expand All @@ -132,7 +171,7 @@ protected function _initErrorHandle()
*/
protected function _initInternationalization()
{
$this->bootstrap(array('Config', 'Database', 'FrontController'));
$this->bootstrap(array('Cache', 'Config', 'Database', 'FrontController'));

/** @var false|Zend_Db_Adapter_Abstract $database */
$database = $this->getResource('Database');
Expand Down Expand Up @@ -343,7 +382,7 @@ protected function _initSass()
*/
protected function _initRouter()
{
$this->bootstrap(array('Config', 'Database', 'FrontController'));
$this->bootstrap(array('Cache', 'Config', 'Database', 'FrontController'));

/** @var Zend_Controller_Front $frontController */
$frontController = $this->getResource('FrontController');
Expand Down
18 changes: 0 additions & 18 deletions core/GlobalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,6 @@ public function preDispatch()
}
}
parent::preDispatch();
if (!$this->isDebug()) {
$frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400, 'cache_id_prefix' => 'midas_');
if (extension_loaded('memcached') || session_save_path() === 'Memcache'
) {
$cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array());
} elseif (extension_loaded('memcache')) {
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array());
} else {
$cacheDir = UtilityComponent::getCacheDirectory().'/db';
if (is_dir($cacheDir) && is_writable($cacheDir)) {
$backendOptions = array('cache_dir' => $cacheDir);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
}
}
if (isset($cache)) {
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
}
}
}

/**
Expand Down

0 comments on commit 198a048

Please sign in to comment.