【发布时间】:2010-08-17 18:43:31
【问题描述】:
我将 Doctrine 1.2 与 Zend Framework 一起使用,它运行良好。现在我想开始使用结果缓存和查询缓存功能来减少为应用程序提供动力的数据库服务器上的负载。哦,我也在使用 Zend_Application 并将代码放在模块中。
无论如何,我在整个 Bootstrap.php 文件中为应用程序本身设置了与 Doctrine 的连接:
protected function _initDoctrine()
{
Zend_Loader_Autoloader::getInstance()->registerNamespace('Doctrine')->pushAutoloader(array('Doctrine', 'autoload'));
$manager = Doctrine_Manager::getInstance();
foreach ($this->_options['doctrine']['attr'] as $key => $val) {
$manager->setAttribute(constant("Doctrine::$key"), $val);
}
$conn = Doctrine_Manager::connection($this->_options['doctrine']['dsn'], 'doctrine');
Doctrine::loadModels($this->_options["doctrine"]["module_directories"]);
}
现在,我花了一些时间阅读 Doctrine 的查询和结果缓存文档和寻找使用 Doctrine 缓存的示例。我发现的似乎非常简单。我将此代码添加到包含 _initDoctrine() 方法的 Bootstrap.php 文件中,在 _initDoctrine() 中
// Set up some caching
$cacheConn = Doctrine_Manager::connection(new PDO('sqlite::memory:'));
$cacheDriver = new Doctrine_Cache_Db(array(
'connection' => $cacheConn,
'tableName' => 'cache'));
$cacheDriver->createTable();
$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
我现在发现正在发生的事情是,应用程序的整个连接现在认为它正在使用 Sqlite 而不是应该使用的 MySQL。这看起来很奇怪,因为我只设置了 ATTR_QUERY_CACHE 属性。
我们将不胜感激有关解决此问题的提示。
【问题讨论】:
标签: zend-framework caching doctrine