A while back I asked a couple questions about Doctrine’s query cache as it did not work as I wanted it to.
Question about why my relationships weren’t being cached:
Doctrine result cache not caching a query with a join
Question about how to get relationships cached using detaching and merging:
Doctrine detaching, caching, and merging
I’m not sure why I didn’t do this sooner, but I just enabled Doctrine’s EchoSQLLogger and I found out that each page is doing three queries when I merge the entities back in.
My entites are user, company, and privilege, with user being the parent to the other two. When I first get the user with company and privilege joined, I run detach on the user and then put it in ApcCache. When I fetch from cache, I do a merge which gives me back the user entity with all of the Doctrine magic intact.
The problem is, when I call merge, it queries for the user, the company, and then privilege. Is this how merge is supposed to work?
Is there any way to cache my user entity with the two relationships intact without making calls to the database?
To anyone (or myself) reading this in the future:
I ended up working around the
PHP Incomplete Classissue by doing separate queries and cache saves for each individual entity. For example my user/company/privilege dilemma in the question. I cache the user, cache the company and override$user['company']with its results, and the same for privilege.This seems to work, but seriously. Doctrine’s caching needs help.