我在Zend Framework中使用Doctrine 1.2,它工作得很好。現在我想開始使用結果緩存和查詢緩存功能來減少爲應用程序提供動力的數據庫服務器上的負載。哦,我也在使用Zend_Application並將代碼放在模塊中。Zend Framework,Doctrine和緩存問題
反正我設置在應用程序本身整體的bootstrap.php文件我的教義連接:
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的緩存的例子。我發現的東西看起來非常簡單。我將此代碼添加到的bootstrap.php文件,其中包含_initDoctrine()方法,裏面_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屬性。
解決此問題的提示將不勝感激。