Doctrine result cache not caching a query with a join

后端 未结 1 557
名媛妹妹
名媛妹妹 2021-01-18 06:47

I\'m using Doctrine 2.2.2 trying to do a query for a user entity along with the user\'s company. I want this query to be cached since the data inside won\'t change often, i

相关标签:
1条回答
  • 2021-01-18 07:33

    I've tested this with Doctrine 2.3 using:

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

    When I run it the first time, I see the actual query in my sql-logger.
    When I run it the second, third, etc time, I don't see anything in my sql-logger.

    My conclusion is it's working fine.

    I guess you either haven't got a result-cache configured, or you have a non-permanent result-cache (like ArrayCache) configured, or it's a bug in Dontrine 2.2.2 (although I can't find anything about it on jira).

    PS: I gather from another question (Doctrine detaching, caching, and merging) that you've 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 changed. In stead of caching the hydrated result, the sql-result is cached (and hydration takes place every run). If you want to cache the hydrated result, you'll have to use the hydration-cache (but be ware that those results are not merged into the EntityManager).

    0 讨论(0)
提交回复
热议问题