aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/caching_with_rails.textile
diff options
context:
space:
mode:
Diffstat (limited to 'railties/guides/source/caching_with_rails.textile')
-rw-r--r--railties/guides/source/caching_with_rails.textile24
1 files changed, 12 insertions, 12 deletions
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 456b0c48a7..940466ecb3 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -27,7 +27,7 @@ page to be fulfilled by the webserver, without ever having to go through the
Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be
applied to every situation (such as pages that need authentication) and since
the webserver is literally just serving a file from the filesystem, cache
-expiration is an issue that needs to be dealt with.
+expiration is an issue that needs to be dealt with.
So, how do you enable this super-fast cache behavior? Simple, let's say you
have a controller called ProductsController and a 'list' action that lists all
@@ -95,7 +95,7 @@ result of the output from a cached copy.
Clearing the cache works in the exact same way as with Page Caching.
Let's say you only wanted authenticated users to edit or create a Product
-object, but still cache those pages:
+object, but still cache those pages:
<ruby>
class ProductsController < ActionController
@@ -138,7 +138,7 @@ created page where different parts of the page need to be cached and expired
differently Rails provides a mechanism called Fragment Caching.
Fragment Caching allows a fragment of view logic to be wrapped in a cache
-block and served out of the cache store when the next request comes in.
+block and served out of the cache store when the next request comes in.
As an example, if you wanted to show all the orders placed on your website
in real time and didn't want to cache that part of the page, but did want
@@ -149,9 +149,9 @@ could use this piece of code:
<% Order.find_recent.each do |o| %>
<%= o.buyer.name %> bought <% o.product.name %>
<% end %>
-
+
<% cache do %>
- All available products:
+ All available products:
<% Product.find(:all).each do |p| %>
<%= link_to p.name, product_url(p) %>
<% end %>
@@ -164,7 +164,7 @@ want to cache multiple fragments per action, you should provide an +action_suffi
<ruby>
<% cache(:action => 'recent', :action_suffix => 'all_products') do %>
- All available products:
+ All available products:
</ruby>
and you can expire it using the +expire_fragment+ method, like so:
@@ -179,7 +179,7 @@ so:
<ruby>
<% cache(:key => ['all_available_products', @latest_product.created_at].join(':')) do %>
- All available products:
+ All available products:
<% end %>
</ruby>
@@ -212,23 +212,23 @@ class StoreSweeper < ActionController::Caching::Sweeper
def after_create(product)
expire_cache_for(product)
end
-
+
# If our sweeper detects that a Product was updated call this
def after_update(product)
expire_cache_for(product)
end
-
+
# If our sweeper detects that a Product was deleted call this
def after_destroy(product)
expire_cache_for(product)
end
-
+
private
def expire_cache_for(record)
# Expire the list page now that we added a new product
expire_page(:controller => '#{record}', :action => 'list')
-
- # Expire a fragment
+
+ # Expire a fragment
expire_fragment(:controller => '#{record}', :action => 'recent', :action_suffix => 'all_products')
end
end