21285 Posts in 5732 Topics by 2602 members
| Go to End | ||
| Author | Topic: | 1615 Views |
-
Re: Do DataObjectSets get cached?

23 February 2010 at 10:32pm
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;
} -
Re: Do DataObjectSets get cached?

24 February 2010 at 12:18am
mateuzs was quite right after all, my mistake for not checking the code more closely. Sorry!
-
Re: Do DataObjectSets get cached?

25 February 2010 at 10:13am
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.
-
Re: Do DataObjectSets get cached?

25 February 2010 at 10:40am
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.
-
Re: Do DataObjectSets get cached?

25 February 2010 at 10:47am Last edited: 25 February 2010 10:48am
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.
-
Re: Do DataObjectSets get cached?

25 February 2010 at 11:04am
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.
| 1615 Views | ||
| Go to Top |


