Invalidating doctrine ORM cache in a rabbitmq-consumer | Symfony2

I have a rabbitmq-consumer implemented in a symfony2 app with the oldsound/rabbitmq-bundle
The app consumes 10 messages at a time and collects data from a mysql-db using the doctrine-querybuilder with filters given in the message-data.
Cachingsystem is APC.
Consider this stripped-down code of the query

$qb = $this->entityManager
    ->getRepository('MyEntity')
    ->createQueryBuilder();
$qb
    ->select('sum(this) as this, sum(that) as that')
    ->andWhere('field in (:values)')
    ->setParameter('values', $filterValues);
$result = $qb
    ->getQuery()
    ->setSingleResult();

This query returns 10 times the same data for the different filter-values. When the consumer restarts and consumes the next 10 messages, I get a different result 10 times again.
I think the doctrine-cache is responsible for this and tried invalidating the cache like so:

$qb = $this->entityManager
    ->getRepository('MyEntity')
    ->createQueryBuilder();
$qb
    ->select('sum(this) as this, sum(that) as that')
    ->andWhere('field in (:values)')
    ->setParameter('values', $filterValues);
$result = $qb
    ->getQuery()
    ->setResultCacheLifetime(0)
    ->setSingleResult();

But with no effect.
I can workaround this behaviour by consuming 1 message at a time only, but this slows down my app to an unacceptable degree.

May anyone hint me in the right direction?

Thanks,
jojo


Source: mysql

Leave a Reply