21489 Posts in 5783 Topics by 2622 members
Page: 1 2
|Go to End||Next >|
21 February 2010 at 6:22am Last edited: 21 February 2010 6:23am
Can anyone tell me if, when I collect a has_many property from within the page controller, the results get cached?
For instance: I have a 'ProjectPage' that has_many 'Projects'. If I call $this->Projects() from the Page controller multiple times, will the results after the first call come from cache? Or should I store the results myself? I'm just not sure...
22 February 2010 at 10:13am
Correct me if I'm wrong, but reading the DataObject::getComponents looks like for the objects in the database it does not get cached. Each call will requery the database.
22 February 2010 at 9:59pm
Thanks for looking into this. I was somewhat under the impression that some dataobjects do get cached, just don't know which ones or when.
If not, wouldn't a template structure like for instance <% if Children%><% control Children %>... or <% if MyProjects %><% control MyProjects %>... (and repeating) be extra expensive?
Or is it only certain sets, like Menu() or Children() that get cached? Or nothing at all, ever?
23 February 2010 at 12:06am Last edited: 23 February 2010 12:10am
I have always assumed that DataObject::get() calls get cached. I don't really have any foundation to make that call, but it would be wholey rediculous for situations like martimiz highlights to generate the same DataObjectSet twice...
However, if they aren't cached, then there is huge room for performance increase here. In fact, I'm going to be chatting with the SS development team specifically about scalability soon and will ask them
23 February 2010 at 1:28am
Great! Please keep us posted on that one - I'll stay subscribed to this post
23 February 2010 at 1:31am
Calls to relationships on a model (aka components) are always cached. This means that if you use $this->Relationship() to retrieve a has/one/many relationship it will be cached. DataObject::get_one calls are also cached, but DataObject::get() calls are not.
23 February 2010 at 3:16am
Thanks, that just what I wanted to know
23 February 2010 at 8:38am
I have had another look (+asked the guru) and no, the calls to getComponents and getManyManyComponents are not cached. The caching code is there, but the cache gets populated only for DataObjects not sitting in the database.
So the answer is: has_many and many_many are not cached (this includes $this->Relationship() call). Has_one are cached though.
Here is a ticket for that: http://open.silverstripe.org/ticket/5103
Page: 1 2
|Go to Top||Next >|