title: Invalidating doctrine ORM cache in a rabbitmq-consumer | Symfony2
body: <p>I have a rabbitmq-consumer implemented in a symfony2 app with the <a href="https://github.com/videlalvaro/RabbitMqBundle" rel="nofollow">oldsound/rabbitmq-bundle</a>
  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</p>
  
  <pre><code>$qb = $this-&gt;entityManager
      -&gt;getRepository('My\Entity')
      -&gt;createQueryBuilder();
  $qb
      -&gt;select('sum(this) as this, sum(that) as that')
      -&gt;andWhere('field in (:values)')
      -&gt;setParameter('values', $filterValues);
  $result = $qb
      -&gt;getQuery()
      -&gt;setSingleResult();
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>$qb = $this-&gt;entityManager
      -&gt;getRepository('My\Entity')
      -&gt;createQueryBuilder();
  $qb
      -&gt;select('sum(this) as this, sum(that) as that')
      -&gt;andWhere('field in (:values)')
      -&gt;setParameter('values', $filterValues);
  $result = $qb
      -&gt;getQuery()
      -&gt;setResultCacheLifetime(0)
      -&gt;setSingleResult();
  </code></pre>
  
  <p>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.</p>
  
  <p>May anyone hint me in the right direction?</p>
  
  <p>Thanks,
  jojo</p>