A
A
Anton Ivanov2014-09-14 03:19:58
PHP
Anton Ivanov, 2014-09-14 03:19:58

How to organize proper caching of entities in Doctrine 2?

Hello.
When I get an entity from the cache, I do
$entityManager->merge($entity)
But while doing this, doctrine makes a database query to get the "managed" entity and merge it with the "cached" one.
I don't need to modify this entity, I just want to get its associations using
$entity->getChildren()
If I don't merge , then getChildren returns nothing. And if I do, then I have an extra request to the database, which I was going to get rid of.
Is it possible to do something like attach to transfer the entity to the managed state, but without querying the database?
PS Using fetch="EAGER" for associations is not an option, since there is no point in storing them in the cache, they are always needed up to date.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Hudinsky, 2015-02-10
@myLizzarD

Unfortunately, requests will always be made, this is how doctrine works, it needs to make an additional request for an entity in order to know about its relationship with other entities. How can she return children to you if she does not know if this entity has them or not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question