Update partial-caching doc to include note on using .Max and .Count together.

This commit is contained in:
madmatt 2013-11-12 16:05:16 +13:00
parent 7ace631499
commit eed29a1557
1 changed files with 5 additions and 2 deletions

View File

@ -61,13 +61,16 @@ For example, if we have a menu, we want that menu to update whenever _any_ page
otherwise. By using aggregates, we can do that like this:
:::ss
<% cached 'navigation', List(SiteTree).max(LastEdited) %>
<% cached 'navigation', List(SiteTree).max(LastEdited), List(SiteTree).Count() %>
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
:::ss
<% cached 'categorylist', List(Category).max(LastEdited) %>
<% cached 'categorylist', List(Category).max(LastEdited), List(Category).Count() %>
Note the use of both .max(LastEdited) and .Count() - this takes care of both the case where an object has been edited
since the cache was last built, and also when an object has been deleted/un-linked since the cache was last built.
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.