Hi!
I have a strange code from repository inspired by
"Also Ocramius (a Doctrine2 devel) say it here
https://groups.google.com/d/msg/doctrine-user/RIeH8ZkKyEY/HnR7h2p0lCQJ"
<https://groups.google.com/d/msg/doctrine-user/RIeH8ZkKyEY/HnR7h2p0lCQJ>
public function findAll()
{
/* @var $query \Doctrine\ORM\Query */
$query = $this->getEntityManager()->createQuery();
if ($query->getQueryCacheDriver()->contains('cache_key')) {
return $query->getQueryCacheDriver()->fetch('cache_key');
}
$query = $this->getEntityManager()
->createQuery(
'SELECT c FROM AppBundle:Culture c'
);
try {
$results = $query->getResult();
$query->getQueryCacheDriver()->save('cache_key', $results, 300);
return $results;
} catch (\Doctrine\ORM\NoResultException $e) {
return null;
}
}
I don't want to use $query->useResultCache(true, 60, 'another_cach_key');
because it parse request 'SELECT c FROM AppBundle:Culture c' which reduces
performance. So I decided to use QueryCacheDriver.
But to get it I have to create empty Query!
$query = $this->getEntityManager()->createQuery();
And for invalidation in controller
$em = $this->getDoctrine()->getManager();
$em->persist($culture);
$em->flush();
// cache invalidation!
$this->getDoctrine()->getEntityManager()->createQuery()->
getQueryCacheDriver()->delete('cache_key');
I think this code smells. But don't know how to fix it! Can anyone show
best practices?
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.