Flatbeat
Flatbeat

Reputation: 123

Doctrine 2 dbal and cache

My question is very stupid but i don't find example of the Doctrine 2 dbal and the cache manager.

I can't use a useResultCache method on a dbal query ?

$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')

Thanks a lot !

Upvotes: 0

Views: 2035

Answers (1)

Flatbeat
Flatbeat

Reputation: 123

I found that :

https://github.com/doctrine/dbal-documentation/blob/master/en/reference/caching.rst

It's working :

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;
}

Upvotes: 1

Related Questions