mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Update with globally keyed fragments
This commit is contained in:
@@ -176,7 +176,25 @@ and you can expire it using the `expire_fragment` method, like so:
|
||||
|
||||
[source, ruby]
|
||||
-----------------------------------------------------
|
||||
expire_fragment(:controller => 'producst', :action => 'recent', :action_suffix => 'all_products)
|
||||
expire_fragment(:controller => 'products', :action => 'recent', :action_suffix => 'all_products)
|
||||
-----------------------------------------------------
|
||||
|
||||
If you don't want the cache block to bind to the action that called it, You can
|
||||
also use globally keyed fragments by calling the cache method with a key, like
|
||||
so:
|
||||
|
||||
[source, ruby]
|
||||
-----------------------------------------------------
|
||||
<% cache(:key => ['all_available_products', @latest_product.created_at].join(':')) do %>
|
||||
All available products:
|
||||
-----------------------------------------------------
|
||||
|
||||
This fragment is then available to all actions in the ProductsController using
|
||||
the key and can be expired the same way:
|
||||
|
||||
[source, ruby]
|
||||
-----------------------------------------------------
|
||||
expire_fragment(:key => ['all_available_products', @latest_product.created_at].join(':'))
|
||||
-----------------------------------------------------
|
||||
|
||||
[More: more examples? description of fragment keys and expiration, etc? pagination?]
|
||||
|
||||
Reference in New Issue
Block a user