aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/caching_with_rails.textile
diff options
context:
space:
mode:
authorEric Carty-Fickes <ericcf@northwestern.edu>2012-05-11 11:12:32 -0500
committerEric Carty-Fickes <ericcf@northwestern.edu>2012-05-11 11:12:32 -0500
commit1004ccc84b16a78d9aa3180e57dda278002fe53e (patch)
tree54e15e31a3b1c1595c5431b0aeace1c9a9fd3ee3 /guides/source/caching_with_rails.textile
parent1b956700ee61e8cc5fab140b38d702767e3d03f1 (diff)
downloadrails-1004ccc84b16a78d9aa3180e57dda278002fe53e.tar.gz
rails-1004ccc84b16a78d9aa3180e57dda278002fe53e.tar.bz2
rails-1004ccc84b16a78d9aa3180e57dda278002fe53e.zip
Clarify expire_action with namespaced controllers
Diffstat (limited to 'guides/source/caching_with_rails.textile')
-rw-r--r--guides/source/caching_with_rails.textile36
1 files changed, 36 insertions, 0 deletions
diff --git a/guides/source/caching_with_rails.textile b/guides/source/caching_with_rails.textile
index e455b504ce..34a100cd3a 100644
--- a/guides/source/caching_with_rails.textile
+++ b/guides/source/caching_with_rails.textile
@@ -229,6 +229,42 @@ class ProductsController < ActionController
end
</ruby>
+Sometimes it is necessary to disambiguate the controller when you call +expire_action+, such as when there are two identically named controllers in separate namespaces:
+
+<ruby>
+class ProductsController < ActionController
+ caches_action :index
+
+ def index
+ @products = Product.all
+ end
+end
+
+module Admin
+ class ProductsController < ActionController
+ cache_sweeper :product_sweeper
+
+ def new
+ @product = Product.new
+ end
+
+ def create
+ @product = Product.create(params[:product])
+ end
+ end
+end
+
+class ProductSweeper < ActionController::Caching::Sweeper
+ observe Product
+
+ def after_create(product)
+ expire_action(:controller => '/products', :action => 'index')
+ end
+end
+</ruby>
+
+Note the use of '/products' here rather than 'products'. If you wanted to expire an action cache for the +Admin::ProductsController+, you would use 'admin/products' instead.
+
h4. SQL Caching
Query caching is a Rails feature that caches the result set returned by each query so that if Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again.