mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #2656 from madmatt/patch-2
Update partial-caching doc to include note on using .Max and .Count together
This commit is contained in:
commit
ad52cc20c1
@ -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:
|
otherwise. By using aggregates, we can do that like this:
|
||||||
|
|
||||||
:::ss
|
:::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
|
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
|
edited
|
||||||
|
|
||||||
:::ss
|
:::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
|
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.
|
whenever the relationship Member::$has_many = array('Favourites' => Favourite') changes.
|
||||||
|
Loading…
Reference in New Issue
Block a user