0

Scenario: In my PHP slim app, I have a class which is used for validation and if that passes I then use a "controller" to perform RESTful style updates.

My question is: If I perform a query and then in an unrelated part of the code perform a query that returns some of/all of the same documents. Does the doctrine document manager reuse the previously retrieved documents?

Thanks in advance! Ben

Ben
  • 251
  • 1
  • 5
  • 13
  • Does your application use the same DocumentManager instance across the app? I am under the impression the DM keeps objects in memory once they have been retrieved. Not much use, though, if nothing is shared between the two parts of the app. – Etzeitet Feb 19 '14 at 19:09
  • Yes its the same document manager, which makes me think the documents might persist for the current execution..? – Ben Feb 19 '14 at 23:06
  • You will have to check, but if the DM is shared between both parts of the app and the unrelated code runs in the same request as the first query, then the DM should already have those documents in memory. I do not know, however, what happens if the second query includes documents not already in memory, i.e., does Doctrine just get the documents it is missing or does it just grab everything again? – Etzeitet Feb 20 '14 at 12:48

1 Answers1

0

Doctrine can be extended to use object caches like Redis to reduce the hits to the database.

We also have added code to our data access layer to reduce queries - this is upstream from Doctrine.

BillyBigPotatoes
  • 1,330
  • 11
  • 23
  • More details about doctrine caching are here: http://docs.doctrine-project.org/en/2.0.x/reference/caching.html – BillyBigPotatoes Feb 19 '14 at 18:20
  • I'm actually already using APC at a Doctrine level... although I wasn't sure if what storing key=>value pairs or compiled PHP. – Ben Feb 19 '14 at 18:34
  • APC offers a PHP Byte code cache and it also does provide a memory based key / value cache. It is a balancing act - if you are using multiple servers / have a lot of data we prefer to use a dedicated object cache like redis or memcache. – BillyBigPotatoes Feb 19 '14 at 18:37