[英]How to make Doctrine lookups like Doctrine_table->find, ->findby* use the query/results cache (doctrine 1.2)
For the first time I have set up a results cache in doctrine 1.24 by applying the following code: 通过应用以下代码,我第一次在准则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 );
This works great for caching DQL quires such as: 这非常适合缓存DQL查询,例如:
enter code here$q = Doctrine_Query::create()
->from('Software s')
->leftJoin('s.Files f')
->useResultCache();
$q->execute();
However, What interests me is how do I cache table lookups such as: 但是,我感兴趣的是如何缓存表查找,例如:
xyzTable::getInstance()->findOneBySufff($stuff);
These are by far more frequent in my application code. 到目前为止,这些在我的应用程序代码中更为常见。 How do I achieve this?
我该如何实现? Additionally, if anyone has a guide for using memcache with doctrine 1.2 I'd be more then happy.
此外,如果有人对在准则1.2中使用Memcache有了指导,我会更高兴。
You have to implement the 您必须实施
xyzTable::getInstance()->findOneBySufff($stuff);
functions in your own xyzTable class. 您自己的xyzTable类中的函数。
class xyzTable extends Doctrine_Table
{
public function findOneByStuff($stuff) {
return $this->createQuery('x')
->select('x.*')
->where('x.stuff = ?', $stuff)
->useResultCache()
->fetchOne();
}
}
Make sure you enable Table creation in your 'doctrine-cli' script 确保在“ doctrine-cli”脚本中启用表创建
....
$doctrine_config['generate_models_options'] =
array('generateTableClasses' => true);
$cli = new Doctrine_Cli($doctrine_config);
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.