Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Do DataObjectSets get cached?

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

Page: 1 2
Go to End
Author Topic: 2102 Views
  • martimiz
    Avatar
    Forum Moderator
    1083 Posts

    Do DataObjectSets get cached? Link to this post

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

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Do DataObjectSets get cached? Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1083 Posts

    Re: Do DataObjectSets get cached? Link to this post

    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?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Do DataObjectSets get cached? Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1083 Posts

    Re: Do DataObjectSets get cached? Link to this post

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

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Do DataObjectSets get cached? Link to this post

    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.

  • martimiz
    Avatar
    Forum Moderator
    1083 Posts

    Re: Do DataObjectSets get cached? Link to this post

    Thanks, that just what I wanted to know

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Do DataObjectSets get cached? Link to this post

    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

    2102 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.