root/trunk/actionpack/lib/action_view/helpers/cache_helper.rb
| Revision 8981, 1.4 kB (checked in by pratik, 9 months ago) |
|---|
| Line | |
|---|---|
| 1 | module ActionView |
| 2 | module Helpers |
| 3 | # This helper to exposes a method for caching of view fragments. |
| 4 | # See ActionController::Caching::Fragments for usage instructions. |
| 5 | module CacheHelper |
| 6 | # A method for caching fragments of a view rather than an entire |
| 7 | # action or page. This technique is useful caching pieces like |
| 8 | # menus, lists of news topics, static HTML fragments, and so on. |
| 9 | # This method takes a block that contains the content you wish |
| 10 | # to cache. See ActionController::Caching::Fragments for more |
| 11 | # information. |
| 12 | # |
| 13 | # ==== Examples |
| 14 | # If you wanted to cache a navigation menu, you could do the |
| 15 | # following. |
| 16 | # |
| 17 | # <% cache do %> |
| 18 | # <%= render :partial => "menu" %> |
| 19 | # <% end %> |
| 20 | # |
| 21 | # You can also cache static content... |
| 22 | # |
| 23 | # <% cache do %> |
| 24 | # <p>Hello users! Welcome to our website!</p> |
| 25 | # <% end %> |
| 26 | # |
| 27 | # ...and static content mixed with RHTML content. |
| 28 | # |
| 29 | # <% cache do %> |
| 30 | # Topics: |
| 31 | # <%= render :partial => "topics", :collection => @topic_list %> |
| 32 | # <i>Topics listed alphabetically</i> |
| 33 | # <% end %> |
| 34 | def cache(name = {}, options = nil, &block) |
| 35 | handler = Template.handler_class_for_extension(current_render_extension.to_sym) |
| 36 | handler.new(@controller).cache_fragment(block, name, options) |
| 37 | end |
| 38 | end |
| 39 | end |
| 40 | end |
Note: See TracBrowser for help on using the browser.