diff options
author | Oscar Del Ben <info@oscardelben.com> | 2012-05-14 13:56:26 -0700 |
---|---|---|
committer | Oscar Del Ben <info@oscardelben.com> | 2012-05-14 13:56:26 -0700 |
commit | f2af398efa40dff20d4841d595bc0366660707cc (patch) | |
tree | 8af0c081de5f2d6cfc1b033c5eefa9954de569dd /guides/source/caching_with_rails.textile | |
parent | 59462c1e310b85569785cf5f491611e670c2755b (diff) | |
parent | 151aa9abae131f1a03513f756aeaef2fc403f9bb (diff) | |
download | rails-f2af398efa40dff20d4841d595bc0366660707cc.tar.gz rails-f2af398efa40dff20d4841d595bc0366660707cc.tar.bz2 rails-f2af398efa40dff20d4841d595bc0366660707cc.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'guides/source/caching_with_rails.textile')
-rw-r--r-- | guides/source/caching_with_rails.textile | 36 |
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. |