我的问题非常愚蠢,但我找不到Doctrine 2 dbal和缓存管理器的例子。
我不能在dbal查询中使用useResultCache方法吗?
$q = \Zend_Registry::get('em')->getConnection()->createQueryBuilder()
->select('f.idprd, f.lprd')
->from('tb_prd', 'f')
->andWhere($q->expr()->eq('f.niveau', $iNiveau))
->orderBy('f.niveau')
非常感谢!
答案 0 :(得分:1)
我发现:
https://github.com/doctrine/dbal-documentation/blob/master/en/reference/caching.rst
它正在运作:
public static function getList() {
$q = \Zend_Registry::get('em')->getConnection()->createQueryBuilder()
->select("np.*")
->from('tb_niv_prd', 'np')
->andWhere("np.lniveau IS NOT NULL")
->andWhere("np.niveau <> 10")
->addOrderBy('np.lniveau', 'ASC');
$stmt = \Zend_Registry::get('em')->getConnection()->executeCacheQuery(
$q->getSql(), array(), array(), new \Doctrine\DBAL\Cache\QueryCacheProfile(0,
"TbNivPrdRepository_getList"));
$aResult = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $aResult;
}