I have this basic model:
When I fetch an entry from the book
table and dump the output:
// no other Doctrine queries were made before this one:
$book = $em->getRepository('Entities\Book')->find(1);
var_dump($book);
I get the Book
entity, but also, a proxied entity for Author
:
object(Entities\Book)#179 (3) {
["id":"Entities\Book":private]=>
int(1)
["title":"Entities\Book":private]=>
string(7) "MyBook1"
["author":"Entities\Book":private]=>
object(Doctrine\Proxy\__CG__\Entities\Author)#171 (5) {
[...] // many more lines of output
My understanding is that the proxied entity for Author
is to be expected, because that is how Doctrine
will lazy load information from the author
table when I do $book->getAuthor()
.
Q1: Do you confirm that the presence of the proxied Author entity is expected at this stage?
However what strikes me, is that when I look at the var_dump
output (which I've uploaded to pastebin for you to see), it contains more than 10,000
lines! Things I was not expecting to find include references to dummy_table1
and dummy_table2
which are not related to book
or author
in the model:
["dummy_table1"]=> // line 1301
object(Doctrine\DBAL\Schema\Table)#194 (10) {
["dummy_table2"]=> // line 1384
object(Doctrine\DBAL\Schema\Table)#191 (10) {
Q2: Is that expected as well?
From there I was wondering: if I want to store the information contained in $book
in cache with serialize
to be re-used later on in my views (I'm not talking about doing some operations with $book
, just outputting some of the properties), it would be insane as I would store about 500KB
for a book title, which brings me to this last question:
Q3: How do you cache the result of your Doctrine queries? Do you serialize the whole entities into cache, do you extract the information you need into an array and then store that array in cache, but if so, doesn't it quickly become cumbersome...?