Jump to:

23001 Posts in 11702 Topics by 2827 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: 1935 Views
  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Do DataObjectSets get cached? Link to this post

    Not so clear after all
    If I understand this correctly from Ingo's comments, calls within template controls are cached in the template layer, so <% if RelatedPages %><% control RelatedPages %>... is OK.

    With a bit of luck, resultsets are cached in MySQL, depending on hosting... But to up performance within the model/controller we should provide our own caching? So to access a resultset from throughout code, we should do something like this:

    protected cachedRelatedPages = null;

    function getRelatedPages() {

    if (empty ($this->cachedRelatedPages)) {
    $this->cachedRelatedPages = $this->RelatedPages();
    }
    return $this->cachedRelatedPages;
    }

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Do DataObjectSets get cached? Link to this post

    mateuzs was quite right after all, my mistake for not checking the code more closely. Sorry!

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Do DataObjectSets get cached? Link to this post

    Well, I just got off the phone to the SilverStripe guys and was told that DataObjects get cached as do relationships. So the database isn't repeatedly hit for the same data over and over if you do <% if Children %> and <% control Children %>.

    If you do ?showqueries in the URL of a page, you will see that there are not identical queries one after the other where you do this in your template either.

    Hope that helps.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Do DataObjectSets get cached? Link to this post

    Actually the Children() method isn't a standard relationship - it's a custom method in the Hierarchy extension which has its own custom caching code.

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Do DataObjectSets get cached? Link to this post

    So if I understand correctly there is a cache in the templating engine which grabs everything.

    This leaves us with:
    - many_manys and has_manys are cached in templates, but not in the php code
    - has_ones are cached both in templates and code (by the virtue of having a dedicated cache)
    - Children are also cached in both (dedicated cache too)

    Is that about right?

    mat.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Do DataObjectSets get cached? Link to this post

    Actually I'm pretty sure that template variables are only cached under certain conditions - one is that an <% if %> statement will cache the variable, but a plain $Foo will not.

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