1

As of newer version of Doctrine2, I know there is Doctrine\ORM\Configuration#setHydrationCacheImpl() to pass such as MemcacheCache, etc.

But how can it be done in container?

I'm using two entity_manager: named "default" and "other".

I first tried defining hydration_cache into config.yml like

doctrine:
    orm:
        default_entity_manager: default
        ...
        entity_managers:
            default:
                ...
                metadata_cache_driver:
                    type: service
                    id: memcache_driver
                ...
                hydration_cache_driver:
                    type: service
                    id: memcache_driver
                ...
            other:
                ...

note: where memcache_driver is defined by me, instanceof Doctrine\Common\Cache\MemcacheCache

then I got Unrecognized options "hydration_cache_driver" under "doctrine.orm.entity_managers.default".

I also tried to directly tweak container in AppKernel#buildContainer, but there's no instances of \Doctrine\ORM\Configuration defined as service, so I couldn't retrieve the Configuration instance.

Any suggestions are welcome.

EDIT:

I'm sure that there is feature for caching hydrated object is re-implemented as of Doctrine 2.2.2.

http://www.doctrine-project.org/jira/browse/DDC-1766

https://github.com/doctrine/doctrine2/blob/2.2.2/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php?source=c

For other simple services, I can easily add methods to call by overwriting whole definitions like

service1:
    ...
    calls:
        [method calls]

but for the entity_manager, I'm not sure how to add method calls to them.

So my question in other words, how to configure orm at lower level like without using semantic configuration?

2 Answers 2

1

In my case, as hydration cache is hardly used, so I decided this time to call Query#setHydrationCacheProfile just before each query is executed.

...
$query = $queryBuilder->getQuery();
$cache = $this->container->get('...'); //instanceof MemcacheCache
$query->setHydrationCacheProfile(new CacheProfile(null, null $cache));
$query->execute();
...
0

There is no such option "hydration_cache_driver", you should use "result_cache_driver" to achieve that.

From Doctrine 2.1, Doctrine can cache results of the queries, but it doesn't cache objects after hydration.

Look at doc about doctrine configuration:

http://symfony.com/doc/master/reference/configuration/doctrine.html

1
  • Thanks for your reply! Yes, it's disabled once, but re-implemented as hydration cache as of 2.2.2. See my edit. Jun 3, 2013 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.