Updating docs to use SiteTree for aggregates with LastEdited example

Using SiteTree is faster, because it doesn't do any joining of Page
to get the aggregate, even though the LastEdited field is only on
SiteTree in the case of Page.
This commit is contained in:
Sean Harvey 2013-05-14 17:12:02 +12:00
parent d5bcbbd66a
commit a4f0983220

View File

@ -58,11 +58,10 @@ To help do this, SilverStripe introduces the concept of Aggregates. These calcul
on sets of `[api:DataObject]`s - the most useful for us being the Max aggregate.
For example, if we have a menu, we want that menu to update whenever _any_ page is edited, but would like to cache it
otherwise. By using aggregates, that's easy
otherwise. By using aggregates, we can do that like this:
:::ss
<% cached 'navigation', List(Page).max(LastEdited) %>
<% cached 'navigation', List(SiteTree).max(LastEdited) %>
If we have a block that shows a list of categories, we can make sure the cache updates every time a category is added or
edited
@ -70,14 +69,12 @@ edited
:::ss
<% cached 'categorylist', List(Category).max(LastEdited) %>
We can also calculate aggregates on relationships. A block that shows the current member's favourites needs to update
whenever the relationship Member::$has_many = array('Favourites' => Favourite') changes.
:::ss
<% cached 'favourites', CurrentMember.ID, CurrentMember.Favourites.max(LastEdited) %>
## Cache key calculated in controller
That last example is a bit large, and is complicating our template up with icky logic. Better would be to extract that