Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine MongoDB result caching

How would one go about caching Doctrine MongoDB results? Looking at the code for Configuration it doesn't appear to have a built in result cache like standard Doctrine, only a query cache.

I have thought of creating my own cache layer in the app but the returned objects are quite heavy as they contain lots of Doctrine logic not needed by the view. How can I pair down the objects so they are effectively just data containers?

like image 606
Mathew Attlee Avatar asked Sep 18 '12 09:09

Mathew Attlee


1 Answers

Doctrine MongoDB ODM does not support query caching, so this is definitely something you'd need to handle in your application for the time being.

If you have an issue with heavy objects, it's most likely the Proxy instances (for referenced documents), as those contain references to internal Doctrine services (e.g. UnitOfWork). If you wanted to cache these efficiently, you'd essentially need to cull those references before storage and then restore them after fetching from the cache. That's likely to be more trouble than its worth, but it would reduce the objects to the data containers that you want.

Alternatively, if you're using the query builder, you could disable hydration and then implement caching for returned array results. Beyond that, you could look into caching views in your application (this is ideal in Symfony2, where one request might hit several controllers, each of which can apply their own caching rules and optionally utilize ESI).

like image 74
jmikola Avatar answered Sep 19 '22 13:09

jmikola