Doctrine result cache does not cache connection request

I am using Doctrine 2.2.2, trying to make a request for a custom object with a user company. I want this request to be cached, since the data inside will not change often, if at all. Below I tried:

$user = $em->createQuery(' SELECT u, c FROM Entities\User u LEFT JOIN u.company c WHERE u.id = :id ')->setParameter('id', $identity)->useResultCache(true, 21600, 'user_' . $identity)->getResult(); 

The user object seems to be cached, but it is still executing a request for the company. Is there a way that I can get both at the same time and include them in the result cache?

I found this one , but it is very old, and its solution did not work for me.

I was asked to have this one , but this view defeats the purpose of the result cache.

+6
source share
1 answer

I tested this with Doctrine 2.3 using:

 $q->setResultCacheDriver( new \Doctrine\Common\Cache\ApcCache() ) ->setResultCacheLifetime( 21600 ) ->setResultCacheId( 'user_' . $identity ); 

When I run it for the first time, I see the actual query in my sql-logger.
When I run this second, third, etc., I do not see anything in my sql-logger.

My conclusion is that it works fine.

I think that you either do not have a result cache configured, or you have an inconsistent result cache (for example, ArrayCache), or a bug in Dontrine 2.2.2 (although I can’t find anything about it on the dir).

PS: I'm going from another question ( Disabling, Caching, and Merging Doctrine ) that you upgraded to Doctrine 2.3. Do you still have this problem?

PPS: Somewhere after Doctrine 2.0 (I think it was 2.2), the result cache has changed. Instead of caching the hydrated result, the sql result is cached (and hydration occurs every time it starts). If you want to cache a hydrated result, you will have to use a hydration cache (but be careful that these results do not merge into the EntityManager).

+1
source

All Articles