Module: ActionController::Caching::Actions

Defined in:
lib/patch_utils/actions.rb

Overview

With this monkey patch, you can also use action cache as the original one. For more informations, refer to actionpack/lib/action_controller/caching/actions.rb in rails3. In rails4, action cache is removed from core, refer to github.com/rails/actionpack-page_caching, and it’s original file is actionpack-action_caching/lib/action_controller/caching/actions.rb in rails4

The original action cache uses request path without query string as cache key, so “/users/show/1” and “/users/show/2” can perform as expected. But “/users/query?name=jody&gender=male” and “/users/query?name=angel&gender=female” will use the same cache key, so the latter request will read cache and return the same response. So, this new feature is, you can use params as a part of the cache key, by configure them with params.

class UsersController < ApplicationController

caches_action :query, :cache_path => {:with_params => [:name, :gender]}
def query
  @user = User.where(:id => params[:id]).first
end

def update
  user = User.where(:id => params[:id]).first
  expire_action(:controller => "users", :action => "query", :with_params => {:name => user.name, :gender => user.gender})
  user.update_attributes(params)
end

end

Defined Under Namespace

Classes: ActionCachePath