title: Symfony 2 cache Doctrine query results
body: <p>I am working on a Symfony2 project using Doctrine. I want to optimise the API performance by adding cache to queries.</p>
  
  <p>I have looked at few options such as:</p>
  
  <ul>
  <li>Symfony annotation cache</li>
  <li>Doctrine cache</li>
  <li>Memcache </li>
  </ul>
  
  <p>Not to sure with which one I should go but to me it seems like caching data at Doctrine level would be most suitable.</p>
  
  <p>Saying that I would like someone to help me or guide me how to set up Doctrine cache and explain how it exactly works.</p>
  
  <p>I.e I have this query:</p>
  
  <pre><code>class QueryFactory
  
      protected $connect;
  
      public function __construct(Connection $connection)
      {
          $this-&gt;connect = $connection;
      }
  
      private function myQuery()
      {
          return $this-&gt;connect-&gt;createQueryBuilder()
              -&gt;select('user_id')
              -&gt;from('users', 'u')
              -&gt;where('u.user_id = 2');
      }
  }
  </code></pre>
  
  <p>How would I add a cache to this query? Is there any Doctrine library I need to inject any thing I need to <code>use</code>?</p>