I have two controllers like this
class New::StoresController < ApplicationController
caches_action :index, cache_path: Proc.new {|c| c.params}, expires_in: cache_time(:long)
caches_action :show, cache_path: Proc.new {|c| c.params}, expires_in: cache_time(:long)
def index
end
def show
# Here I use param[:store], params[:locale] and params[:ref]
end
end
class New::StoreReviewsController < ApplicationController
def create
expire_action controller: '/new/stores', action: :show, \
store:params[:store], locale:"en", ref:"stores"
end
end
I want to expire action New::StoresController#show on creation of a new StoreReview.
When the show action of Store is executed, the cache reads the following
Cache read: views/localhost:3000/en/stores/store-name
Read fragment views/localhost:3000/en/stores/store-name
While expire_action expires this fragment
Expire fragment views/localhost:3000/en/search?action=show&controller=new/stores&ref=stores Cache delete: views/localhost:3000/en/search?action=show&controller=new/stores
The question is should I use expire_fragment
instead of expire_action
as mentioned here ? rails 3 caching: expire action for named route
Also if I want to cache the action but not with all params what is the best way to do it?
Currently that's what I am doing
caches_action :show, cache_path: Proc.new {|c| c.params.select{ |p| [:controller,:action ,"locale", "store"].include? p} }, expires_in: cache_time(:long)