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...
23 February 2010 at 12:06am
(Last edited: 23 February 2010 12:10am),
I have always assumed that [url=http://doc.silverstripe.org/doku.php?id=datamodel#querying_data]DataObject::get()[/url] calls get cached. I don't really have any foundation to make that call, but it would be wholey rediculous for situations like [url=http://www.silverstripe.org/ForumMemberProfile/show/3377]martimiz[/url] highlights to generate the same [url=http://doc.silverstripe.org/doku.php?id=DataobjectSet]DataObjectSet[/url] 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: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 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