我将application.ini缓存如下:
确保您有以下目录(您的缓存目录):
/application/data/cache
我扩展
Zend_Application
My_Application
,请参见代码:
<?php
require_once 'Zend/Application.php';
class My_Application extends Zend_Application
{
protected $_cacheConfig = false;
protected $_cacheOptions = array(
'frontendType' => 'File',
'backendType' => 'File',
'frontendOptions' => array(),
'backendOptions' => array()
);
public function __construct($environment, $options = null)
{
if (is_array($options) && isset($options['configFile'])) {
$this->_cacheConfig = true;
if (isset($options['cacheOptions']))
$this->_cacheOptions =
array_merge($this->_cacheOptions, $options['cacheOptions']);
$options = $options['configFile'];
}
parent::__construct($environment, $options);
}
protected function _loadConfig($file)
{
if (!$this->_cacheConfig)
return parent::_loadConfig($file);
require_once 'Zend/Cache.php';
$cache = Zend_Cache::factory(
$this->_cacheOptions['frontendType'],
$this->_cacheOptions['backendType'],
array_merge(array(
'master_file' => $file,
'automatic_serialization' => true
), $this->_cacheOptions['frontendOptions']),
array_merge(array(
'cache_dir' => APPLICATION_PATH . '/data/cache'
), $this->_cacheOptions['backendOptions'])
);
$config = $cache->load('Zend_Application_Config');
if (!$config) {
$config = parent::_loadConfig($file);
$cache->save($config, 'Zend_Application_Config');
}
return $config;
}
}
public
根)到:
<?php
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'My/Application.php';
$application = new My_Application(
APPLICATION_ENV,
array(
'configFile' => APPLICATION_PATH . '/configs/application.ini'
)
);
$application->bootstrap()
->run();
重新加载页面,您将看到缓存的ini文件。祝你好运。