通过应用以下代码,我第一次在doctrine 1.24中设置了一个结果缓存:
$servers = array(
'host' => 'localhost',
'port' => 11211,
'persistent' => true
);
$cacheDriver = new Doctrine_Cache_Memcache(
array(
'servers' => $servers,
'compression' => false
)
);
$manager->setAttribute(Doctrine::ATTR_RESULT_CACHE,$cacheDriver);
$manager->setAttribute(Doctrine::ATTR_RESULT_CACHE_LIFESPAN, 3600 );这对于缓存DQL查询非常有用,例如:
enter code here$q = Doctrine_Query::create()
->from('Software s')
->leftJoin('s.Files f')
->useResultCache();
$q->execute();但是,我感兴趣的是如何缓存表查找,例如:
xyzTable::getInstance()->findOneBySufff($stuff);到目前为止,这些在我的应用程序代码中要频繁得多。我该如何实现这一点?此外,如果有人对memcache的1.2原理有一个使用指南,我会很高兴。
发布于 2012-10-16 02:58:17
您必须实现
xyzTable::getInstance()->findOneBySufff($stuff);函数在您自己的xyzTable类中。
class xyzTable extends Doctrine_Table
{
public function findOneByStuff($stuff) {
return $this->createQuery('x')
->select('x.*')
->where('x.stuff = ?', $stuff)
->useResultCache()
->fetchOne();
}
}请确保在‘enable cli’脚本中启用了表创建
....
$doctrine_config['generate_models_options'] =
array('generateTableClasses' => true);
$cli = new Doctrine_Cli($doctrine_config);
....https://stackoverflow.com/questions/12817559
复制相似问题