1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
public function countCabinets()
{
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addScalarResult('count_cabinets', 'count_cabinets', 'integer');
$query = $this->_em->createNativeQuery('
SELECT
COUNT(c.id) AS count_cabinets
FROM
cabinet c
WHERE
c.date_suppression IS NULL
', $rsm);
$id = $query->getSQL();
/*
* On charge le moteur "APC Cache"
*/
$cacheDriver = new \Doctrine\Common\Cache\ApcCache();
/*
* Si le résultat de la requête est déjà en cache, on la renvoit
*/
if ($cacheDriver->contains($id)) {
return $cacheDriver->fetch($id);
} else {
/*
* Sinon, on enregistre la requête en cache
*/
$result = $query->getSingleScalarResult();
$cacheDriver->save($id, $result);
return $result;
}
} |
Partager