Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Do DataObjectSets get cached?


Go to End
Reply


14 Posts   2182 Views

Avatar
martimiz

Forum Moderator, 1105 Posts

21 February 2010 at 6:22am

Edited: 21/02/2010 6:23am

Hi all,

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...

Avatar
MateuszU

Community Member, 89 Posts

22 February 2010 at 10:13am

Hi,
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.

mat

Avatar
martimiz

Forum Moderator, 1105 Posts

22 February 2010 at 9:59pm

Hi Mat,

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?

Avatar
Pigeon

Community Member, 243 Posts

23 February 2010 at 12:06am

Edited: 23/02/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 :)

Avatar
martimiz

Forum Moderator, 1105 Posts

23 February 2010 at 1:28am

Great! Please keep us posted on that one - I'll stay subscribed to this post :-)

Avatar
ajshort

Community Member, 244 Posts

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.

Avatar
martimiz

Forum Moderator, 1105 Posts

23 February 2010 at 3:16am

Thanks, that just what I wanted to know :-)

Avatar
MateuszU

Community Member, 89 Posts

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

mat

Go to Top