【发布时间】:2015-03-24 21:06:07
【问题描述】:
我是 Zend 的初学者,在尝试缓存数据库查询结果时遇到了一些问题。
我已经阅读了很多类似http://framework.zend.com/manual/1.12/en/zend.db.table.html 的论坛和文档(示例 31),但它们通常都说要在构造方法中设置 $defaultMetadataCache。
我做到了,但是似乎没有读取缓存,因为我没有获得更好的性能。
这是我的文件 ./library/Zend/Db/Table/Abstract.php 的构造
public function __construct($config = array())
{
/**
* Allow a scalar argument to be the Adapter object or Registry key.
*/
if (!is_array($config)) {
$config = array(self::ADAPTER => $config);
}
if ($config) {
$this->setOptions($config);
}
$config_temp = new Zend_Config_Ini(APPLICATION_PATH . '/configs/config.ini', APPLICATION_ENV);
$cache_lifetime = (isset($config_temp->cache->lifetime) && $config_temp->cache->lifetime) ? $config_temp->cache->lifetime : 300;
$cache_dir = (isset($config_temp->cache->dir) && $config_temp->cache->dir) ? $config_temp->cache->dir : '/tmp/hookit/cache/';
if(!is_dir($cache_dir))
mkdir ($cache_dir, 0755, true);
$frontendOptions = array('lifetime' => $cache_lifetime, 'automatic_serialization' => true);
$backendOptions = array('cache_dir' => $cache_dir);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
if(!self::getDefaultMetadataCache()){
self::setDefaultMetadataCache($cache);
}
$this->_setup();
$this->init();
}
【问题讨论】:
标签: php caching zend-framework