我有两个像这样的控制器
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
我希望在创建新的StoreReview时将动作New :: StoresController #show结束。
执行Store的show动作时,缓存会读取以下内容
缓存读取:views / localhost:3000 / en / stores / store-name
读取片段视图/ localhost:3000 / en / stores / store-name
虽然expire_action过期了这个片段
过期片段视图/ localhost:3000 / en / search?action = show&amp; controller = new / stores&amp; ref = stores 缓存删除:views / localhost:3000 / en / search?action = show&amp; controller = new / stores
问题是我应该使用expire_fragment
代替此处提到的expire_action
吗? rails 3 caching: expire action for named route
另外,如果我想缓存动作而不是所有参数,那么最好的方法是什么?
目前我正在做的事情
caches_action :show, cache_path: Proc.new {|c| c.params.select{ |p| [:controller,:action ,"locale", "store"].include? p} }, expires_in: cache_time(:long)
答案 0 :(得分:1)
我已经得到了答案。
默认情况下caches_action
会忽略参数。
为了让正确的片段过期,我做了以下
expire_action store_url(host: my_host, store: store_name, locale: locale])