mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
d5bcbbd66a
commit
a4f0983220
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user