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

Commit 198a048

Browse files
author
Jamie Snape
committed
Move cache initialization to bootstrap
1 parent 1281ee1 commit 198a048

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

core/Bootstrap.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function _initDoctype()
3030
$this->bootstrap('view');
3131

3232
/** @var Zend_View $view */
33-
$view = $this->getResource('view');
33+
$view = $this->getResource('View');
3434
$view->doctype('XHTML1_STRICT');
3535
}
3636

@@ -109,6 +109,45 @@ protected function _initDatabase()
109109
return false;
110110
}
111111

112+
/**
113+
* Initialize the cache.
114+
*
115+
* @return false|Zend_Cache_Core
116+
*/
117+
protected function _initCache()
118+
{
119+
$this->bootstrap('Config', 'Database');
120+
121+
if (Zend_Registry::get('configGlobal')->get('environment', 'production') === 'production') {
122+
$frontendOptions = array(
123+
'automatic_serialization' => true,
124+
'lifetime' => 86400,
125+
'cache_id_prefix' => 'midas_',
126+
);
127+
128+
if (extension_loaded('memcached') || session_save_path() === 'Memcache') {
129+
$cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array());
130+
} elseif (extension_loaded('memcache')) {
131+
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array());
132+
} else {
133+
$cacheDir = UtilityComponent::getCacheDirectory().'/db';
134+
135+
if (is_dir($cacheDir) && is_writable($cacheDir)) {
136+
$backendOptions = array('cache_dir' => $cacheDir);
137+
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
138+
}
139+
}
140+
141+
if ($cache !== false) {
142+
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
143+
}
144+
}
145+
146+
Zend_Registry::set('cache', $cache);
147+
148+
return $cache;
149+
}
150+
112151
/** Initialize the error handler. */
113152
protected function _initErrorHandle()
114153
{
@@ -132,7 +171,7 @@ protected function _initErrorHandle()
132171
*/
133172
protected function _initInternationalization()
134173
{
135-
$this->bootstrap(array('Config', 'Database', 'FrontController'));
174+
$this->bootstrap(array('Cache', 'Config', 'Database', 'FrontController'));
136175

137176
/** @var false|Zend_Db_Adapter_Abstract $database */
138177
$database = $this->getResource('Database');
@@ -343,7 +382,7 @@ protected function _initSass()
343382
*/
344383
protected function _initRouter()
345384
{
346-
$this->bootstrap(array('Config', 'Database', 'FrontController'));
385+
$this->bootstrap(array('Cache', 'Config', 'Database', 'FrontController'));
347386

348387
/** @var Zend_Controller_Front $frontController */
349388
$frontController = $this->getResource('FrontController');

core/GlobalController.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,6 @@ public function preDispatch()
144144
}
145145
}
146146
parent::preDispatch();
147-
if (!$this->isDebug()) {
148-
$frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400, 'cache_id_prefix' => 'midas_');
149-
if (extension_loaded('memcached') || session_save_path() === 'Memcache'
150-
) {
151-
$cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array());
152-
} elseif (extension_loaded('memcache')) {
153-
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array());
154-
} else {
155-
$cacheDir = UtilityComponent::getCacheDirectory().'/db';
156-
if (is_dir($cacheDir) && is_writable($cacheDir)) {
157-
$backendOptions = array('cache_dir' => $cacheDir);
158-
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
159-
}
160-
}
161-
if (isset($cache)) {
162-
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
163-
}
164-
}
165147
}
166148

167149
/**

0 commit comments

Comments
 (0)